2013-04-18 54 views
2

我尝试从ulr获取json数据。在android中未得到完整的http响应

我正在测试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(); 

} 

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

请任何人帮助我。

+0

在清单文件中添加Internet权限。 – 2013-04-18 05:17:58

+0

@VivekKumarSrivastava所有权限添加和我的代码工作正常,但问题是没有得到完整的响应从webservice。 – Hemant 2013-04-18 05:19:36

+0

你可以使用String s = EntityUtils.toString(response.getEntity());并让我知道如果这项工作。 – 2013-04-18 05:24:32

回答

2

试试这个...

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

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

有时它不打印在控制台上充分反应,但你得到你的变量全力应对...

解决方案:完全数据不logcat的或控制台中显示

+0

它的工作,但没有得到充分的答复。 – Hemant 2013-04-18 05:52:52

+1

你的回应是非常大的限制变量?意味着你得到的答复一半或没有得到任何答复请指定...?谢谢 – SBJ 2013-04-18 05:54:06

+0

获得了一半的回应。因为我的回复大小非常大。 – Hemant 2013-04-18 05:58:53