我在Android中發現HTTP POST問題。Android中的HTTP Post問題
問題發生在代碼正在讀取響應時,它無法獲取我想要檢索的完整網頁代碼。
我只檢索一塊網頁。
下面是代碼:
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(URL);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("text", "06092010"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response;
response=httpclient.execute(httppost);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String s = "";
String line = reader.readLine();
while(line != null){
s += line+"\n";
line = reader.readLine();
}
Log.d("Street", "Result: "+s);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
Log.d("Street", e.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
Log.d("Street", e.toString());
} catch (Exception e) {
Log.d("Street", e.toString());
}
請將此標記爲已回答,然後使用此帖作爲答案。幫助保持StackOverflow整潔! – 2010-11-08 01:44:42