對不起,我的英文。我有這個問題:當我使用httpclient時,我不能從服務器獲得完整的消息。這是我的代碼:httpclient android not full message
DefaultHttpClient hc = new DefaultHttpClient();
HttpPost postMethod = new HttpPost(params[0]);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(params.length-1);
for(int i=1;i<params.length;i++){
int endF=params[i].indexOf("=");
nameValuePairs.add(new BasicNameValuePair(params[i].substring(0, endF),
params[i].substring(endF+1, params[i].length())));
}
// Url Encoding the POST parameters
try {
postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
} catch (UnsupportedEncodingException e) {
// writing error to Log
e.printStackTrace();
}
try {
HttpResponse resp = hc.execute(postMethod);
BufferedReader in = new BufferedReader(new InputStreamReader(resp.getEntity().getContent()));
StringBuffer sbuffer = new StringBuffer("");
String line = "";
while ((line = in.readLine()) != null) {
sbuffer.append(line + "\n");
}
in.close();
response = sbuffer.toString();
而我得到的JSON甚至不會被「}」關閉。簡單它被切斷了。下一部分在哪裏?以及我如何獲得它?
您好,歡迎堆棧溢出!你有沒有考慮切換到'HttpURLConnection'?這是谷歌推薦的Gingerbread和:http://android-developers.blogspot.com.es/2011/09/androids-http-clients.html – atxe