【发布时间】:2010-09-06 18:28:14
【问题描述】:
我在 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());
}
【问题讨论】:
标签: html android http post httpclient