没有得到响应响应= httpclient.execute(要求); [英] not getting response response = httpclient.execute(request);

查看:1060
本文介绍了没有得到响应响应= httpclient.execute(要求);的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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;
    }

}

这是在code,但在 响应= http.client.execute(要求) 没有得到回应。我找不到原因。

This is the code but on response = http.client.execute(request) doesn't get response. I couldn't find why.

推荐答案

您应该异步调用的方法。然后,它会与同一code。 这两条线code添加到您的项目

You should call the method asynchronously. Then it will work with the same code. Add these two lines of code to your project

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

和 使最低SDK版本9

and make minimum sdk version to 9

这篇关于没有得到响应响应= httpclient.execute(要求);的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆