关于ZAKER 融媒体解决方案 合作 加入

android – 没有得到响应响应 = httpclient.execu.

CocoaChina 10-22

public class HTTPPoster { public static HttpResponse doPost ( String url, JSONObject c ) throws ClientProtocolException, IOException { HttpClient httpclient = new DefaultHttpClient ( ) ; HttpPost request = new HttpPost ( url ) ; HttpEntity entity; StringEntity s = new StringEntity ( c.toString ( ) ) ; s.setContentEncoding ( ( Header ) new BasicHeader ( HTTP.DEFAULT_CONTENT_CHARSET, "application/json" ) ) ; entity = s; request.setEntity ( entity ) ; HttpResponse response; response = httpclient.execute ( request ) ; return response; }}

这是代码 , 但在响应 = http.client.execute ( 请求 ) 没有得到响应 . 我找不到原因 .

最佳答案

您应该异步调用该方法 . 然后它将使用相同的代码 .

将这两行代码添加到项目中

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder ( ) .permitAll ( ) .build ( ) ; StrictMode.setThreadPolicy ( policy ) ;

将最小 sdk 版本设为 9

以上内容由"CocoaChina"上传发布 查看原文
相关标签 android