Android ICS HTTP POST
我知道这个问题已经被问过很多次了。我也搜索了论坛,但是找不到我想要的答案 该代码适用于许多android版本,但不适用于3.0或更高版本。来自\u服务器的字符串响应\u=nullAndroid ICS HTTP POST,android,http-post,android-3.0-honeycomb,ice,Android,Http Post,Android 3.0 Honeycomb,Ice,我知道这个问题已经被问过很多次了。我也搜索了论坛,但是找不到我想要的答案 该代码适用于许多android版本,但不适用于3.0或更高版本。来自\u服务器的字符串响应\u=null // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(file_n_folder.URL_POST)
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(file_n_folder.URL_POST);
//Log.d("URL",file_n_folder.URL_POST);
try {
JSONArray postjson = new JSONArray();
postjson.put(obj);
// Post the data:
httppost.setHeader("json",obj.toString());
httppost.getParams().setParameter("jsonpost",postjson);
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
// for JSON:
if(response != null){
InputStream is = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
response_from_server = sb.toString();
//Log.d("RESPONSE FROM SERVER",response_from_server);
return response_from_server;
}
}catch (ClientProtocolException e){
Log.d("EXCEPTION line 94",e.getMessage());
}catch (IOException e){
Log.d("EXCEPTION line 96",e.getMessage());
}
return response_from_server;
它总是使httpclient.execute(httppost)上的应用程序崩溃
你们能给我建议一下,怎么解决这个问题吗
Thanx这是因为,由于蜂巢,您有义务在UI线程之外进行联网。将网络移动到IntentService或AsyncTask
请参阅本文:我可以看看如何实现这一点的示例吗?