【发布时间】:2015-07-23 20:09:07
【问题描述】:
我有一个 AsyncTask 如下:
@Override
protected ArrayList<String> doInBackground(String... params) {
ArrayList<String> result=new ArrayList<>();
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(Constants.URL);
// Add your data
List<BasicNameValuePair> nameValuePairs = new ArrayList<BasicNameValuePair>(
2);
nameValuePairs.add(new BasicNameValuePair("id",params[0]));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
HttpEntity httpEntity = response.getEntity();
inputStream = httpEntity.getContent();
// deal with response here
....
} catch (Exception e) {
Log.e("Debug", e + " " + e.getMessage());
}
return result;
}
但是,在 Jellybean 上,应用程序运行一段时间后,代码只运行到 httpclient.execute(httppost) 并停在那里。
谁能帮我解决这个问题?
【问题讨论】:
-
LogCat 上显示了一些消息?
-
你在哪里调用这个 AsyncTask 并且你在调用 postExecute 方法? doInBackground() 中的 UI 没有任何反应
标签: android http-post httpclient