Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private class PublishBuild extends AsyncTask<String, Void, Integer> {
- private String result;
- @Override
- protected void onPreExecute()
- {
- }
- @Override
- protected Integer doInBackground(String... arg0)
- {
- result = "";
- int responseCode = 0;
- InputStream is = null;
- try
- {
- HttpClient client = new DefaultHttpClient();
- HttpPost httppost = new HttpPost("url");
- List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
- nameValuePairs.add(new BasicNameValuePair("items", arg0[0]));
- nameValuePairs.add(new BasicNameValuePair("buildName", arg0[1]));
- nameValuePairs.add(new BasicNameValuePair("buildDescript", arg0[2]));
- httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
- int executeCount = 0;
- HttpResponse response;
- do
- {
- executeCount++;
- response = client.execute(httppost);
- responseCode = response.getStatusLine().getStatusCode();
- } while (executeCount < 50 && responseCode == 408);
- Log.d("256 Design", "statusCode: " + responseCode);
- HttpEntity entity = response.getEntity();
- is = entity.getContent();
- try{
- BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
- StringBuilder sb = new StringBuilder();
- String line = null;
- while ((line = reader.readLine()) != null) {
- sb.append(line + "\n");
- }
- is.close();
- result=sb.toString();
- }catch(Exception e) {
- Log.e("log_tag", "Error converting result "+e.toString());
- }
- }
- catch (Exception e) {
- responseCode = 408;
- e.printStackTrace();
- }
- return responseCode;
- }
- @Override
- protected void onPostExecute(Integer headerCode)
- {
- if(headerCode == 408)
- Toast.makeText(context, "Error connecting to server, please try again later!", Toast.LENGTH_LONG).show();
- else
- userFeedback(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement