@Override protected String doInBackground(Boolean... params) { Integer redLevel = uiMan.getRed(); Integer greenLevel = uiMan.getGreen(); Integer blueLevel = uiMan.getBlue(); Integer trans = uiMan.getTransition(); Integer time = uiMan.getTime(); if (!params[0]) trans = -1; Log.d( "LightRequest", String.format( "R:%d, G:%d, B:%d, Trans:%d, Time:%d", redLevel, greenLevel, blueLevel, trans, time)); try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(serviceURI); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("r", redLevel.toString())); nameValuePairs.add(new BasicNameValuePair("g", greenLevel.toString())); nameValuePairs.add(new BasicNameValuePair("b", blueLevel.toString())); nameValuePairs.add(new BasicNameValuePair("trans", trans.toString())); nameValuePairs.add(new BasicNameValuePair("time", time.toString())); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); StringBuilder sb = new StringBuilder(); String line; BufferedReader reader = new BufferedReader(new InputStreamReader(instream, "UTF-8")); while ((line = reader.readLine()) != null) { sb.append(line).append("\n"); } String result = sb.toString(); return result; } } catch (ClientProtocolException e) { Log.e(e.getClass().toString(), e.getMessage()); } catch (IOException e) { Log.e(e.getClass().toString(), e.getMessage()); } catch (IllegalArgumentException e) { Log.e(e.getClass().toString(), e.getMessage()); } catch (Exception e) { Log.e(e.getClass().toString(), e.getMessage()); } return "null"; }
public void sendFromInputStream(InputStream input, long length) { client = new MyHttpClient(context); HttpPost httppost = new HttpPost("https://csl.ece.iastate.edu/android/appdata.php"); httppost.setEntity(new InputStreamEntity(input, length)); HttpResponse response; try { response = client.execute(httppost); Log.v("mark", "SSLCommunication HttpResponse:" + response.toString()); } catch (ClientProtocolException e) { Log.v( "mark", "SSLCommunication sendFile ClientProtocolException:" + e.getClass() + " with " + e.getMessage()); } catch (IOException e) { Log.v( "mark", "SSLCommunication sendFile IOException:" + e.getClass() + " with " + e.getMessage()); } }
@Override public void send(CrashReportData data) throws ReportSenderException { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://oops.tomahawk-player.org/addreport.php"); StringBuilder body = new StringBuilder(); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add( new BasicNameValuePair("Version", data.getProperty(ReportField.APP_VERSION_NAME))); nameValuePairs.add(new BasicNameValuePair("BuildID", data.getProperty(ReportField.BUILD))); nameValuePairs.add(new BasicNameValuePair("ProductName", "tomahawk-android")); nameValuePairs.add(new BasicNameValuePair("Vendor", "Tomahawk")); nameValuePairs.add( new BasicNameValuePair("timestamp", data.getProperty(ReportField.USER_CRASH_DATE))); for (NameValuePair pair : nameValuePairs) { body.append("--thkboundary\r\n"); body.append("Content-Disposition: form-data; name=\""); body.append(pair.getName()).append("\"\r\n\r\n").append(pair.getValue()).append("\r\n"); } body.append("--thkboundary\r\n"); body.append("Content-Disposition: form-data; name=\"upload_file_minidump\"; filename=\"") .append(data.getProperty(ReportField.REPORT_ID)) .append("\"\r\n"); body.append("Content-Type: application/octet-stream\r\n\r\n"); body.append("============== Tomahawk Exception Report ==============\r\n\r\n"); body.append("Report ID: ").append(data.getProperty(ReportField.REPORT_ID)).append("\r\n"); body.append("App Start Date: ") .append(data.getProperty(ReportField.USER_APP_START_DATE)) .append("\r\n"); body.append("Crash Date: ") .append(data.getProperty(ReportField.USER_CRASH_DATE)) .append("\r\n\r\n"); body.append("--------- Phone Details ----------\r\n"); body.append("Phone Model: ").append(data.getProperty(ReportField.PHONE_MODEL)).append("\r\n"); body.append("Brand: ").append(data.getProperty(ReportField.BRAND)).append("\r\n"); body.append("Product: ").append(data.getProperty(ReportField.PRODUCT)).append("\r\n"); body.append("Display: ").append(data.getProperty(ReportField.DISPLAY)).append("\r\n"); body.append("-----------------------------------\r\n\r\n"); body.append("----------- Stack Trace -----------\r\n"); body.append(data.getProperty(ReportField.STACK_TRACE)).append("\r\n"); body.append("-----------------------------------\r\n\r\n"); body.append("------- Operating System ---------\r\n"); body.append("App Version Name: ") .append(data.getProperty(ReportField.APP_VERSION_NAME)) .append("\r\n"); body.append("Total Mem Size: ") .append(data.getProperty(ReportField.TOTAL_MEM_SIZE)) .append("\r\n"); body.append("Available Mem Size: ") .append(data.getProperty(ReportField.AVAILABLE_MEM_SIZE)) .append("\r\n"); body.append("Dumpsys Meminfo: ") .append(data.getProperty(ReportField.DUMPSYS_MEMINFO)) .append("\r\n"); body.append("-----------------------------------\r\n\r\n"); body.append("-------------- Misc ---------------\r\n"); body.append("Package Name: ").append(data.getProperty(ReportField.PACKAGE_NAME)).append("\r\n"); body.append("File Path: ").append(data.getProperty(ReportField.FILE_PATH)).append("\r\n"); body.append("Android Version: ") .append(data.getProperty(ReportField.ANDROID_VERSION)) .append("\r\n"); body.append("Build: ").append(data.getProperty(ReportField.BUILD)).append("\r\n"); body.append("Initial Configuration: ") .append(data.getProperty(ReportField.INITIAL_CONFIGURATION)) .append("\r\n"); body.append("Crash Configuration: ") .append(data.getProperty(ReportField.CRASH_CONFIGURATION)) .append("\r\n"); body.append("Settings Secure: ") .append(data.getProperty(ReportField.SETTINGS_SECURE)) .append("\r\n"); body.append("User Email: ").append(data.getProperty(ReportField.USER_EMAIL)).append("\r\n"); body.append("User Comment: ").append(data.getProperty(ReportField.USER_COMMENT)).append("\r\n"); body.append("-----------------------------------\r\n\r\n"); body.append("---------------- Logs -------------\r\n"); body.append("Logcat: ").append(data.getProperty(ReportField.LOGCAT)).append("\r\n\r\n"); body.append("Events Log: ").append(data.getProperty(ReportField.EVENTSLOG)).append("\r\n\r\n"); body.append("Radio Log: ").append(data.getProperty(ReportField.RADIOLOG)).append("\r\n"); body.append("-----------------------------------\r\n\r\n"); body.append("=======================================================\r\n\r\n"); body.append("--thkboundary\r\n"); body.append( "Content-Disposition: form-data; name=\"upload_file_tomahawklog\"; filename=\"Tomahawk.log\"\r\n"); body.append("Content-Type: text/plain\r\n\r\n"); body.append(data.getProperty(ReportField.LOGCAT)); body.append("\r\n--thkboundary--\r\n"); httppost.setHeader("Content-type", "multipart/form-data; boundary=thkboundary"); try { httppost.setEntity(new StringEntity(body.toString())); httpclient.execute(httppost); } catch (ClientProtocolException e) { Log.e(TAG, "send: " + e.getClass() + ": " + e.getLocalizedMessage()); } catch (IOException e) { Log.e(TAG, "send: " + e.getClass() + ": " + e.getLocalizedMessage()); } }