在android中没有获得完整的http响应

时间:2013-04-18 05:13:22

标签: android

我尝试从ulr获取json数据。

我正在测试firefox海报附加工作中的url,得到完整的响应。

但是 android没有得到完整的http响应。

这是我的代码

HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); // Timeout
                                                                        // Limit
HttpResponse response;
JSONObject json = new JSONObject();

try {
    HttpPost post = new HttpPost(API.ALL_PROPERTY_BUY);

    /*
     * json.put("fId", fname); json.put("fId", lname);
     */
    StringEntity se = new StringEntity(json.toString());
    se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE,"application/json"));
    post.setEntity(se);
    response = client.execute(post);

    /* Checking response */
    if (response != null) {
        InputStream in = response.getEntity().getContent(); // Get the
                                                            // data in
                                                            // the
                                                            // entity
        // System.out.println("Response is:"+ in.toString());
        InputStreamReader isr = new InputStreamReader(in);
        BufferedReader br = new BufferedReader(isr);

        String s = new String();
        temps = new String();
        while ((s = br.readLine()) != null) {
            System.out.println("response is :" + s);

        }



    }


} catch (Exception e) {
    e.printStackTrace();

}

我也是从谷歌搜索并尝试代码,但没有解决我的问题。

请任何人帮助我。

1 个答案:

答案 0 :(得分:2)

试试这个......

    StringBuffer stringBuffer = new StringBuffer();
            while ((s = br.readLine()) != null) {
                stringBuffer.append(s);
            }

 System.out.println("response is :" + stringBuffer);

有时它不能在控制台上打印完整的响应,但是你的变量得到了完整的响应......

解决方案:Logcat或控制台上未显示完整数据