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;
}
}
这是代码,但 response = http.client.execute(request)
没有得到响应。我找不到原因。
最佳答案
您应该异步调用该方法。然后它将使用相同的代码。 将这两行代码添加到您的项目中
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
和 将最低sdk版本设置为9
关于android - 没有得到响应response = httpclient.execute(request);,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6939122/