我嘗試從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();
}
我也是從谷歌搜索,嘗試與代碼但不解決我的問題。
請任何人幫助我。
在清單文件中添加Internet權限。 – 2013-04-18 05:17:58
@VivekKumarSrivastava所有權限添加和我的代碼工作正常,但問題是沒有得到完整的響應從webservice。 – Hemant 2013-04-18 05:19:36
你可以使用String s = EntityUtils.toString(response.getEntity());並讓我知道如果這項工作。 – 2013-04-18 05:24:32