http://www.licai.com/xuetang/CiDian.aspx?dj=1&type=&page=1
client.executeMethod(get);
//
String statusText = get.getStatusText();
//System.out.println("Test.main():--->" + statusText);
System.out.println("Test.main():--->" + new String(get.getResponseBodyAsString().getBytes("GB2312"), "UTF-8"));
InputStream in = get.getResponseBodyAsStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in, charset));
String tempbf;
html = new StringBuffer(100);
while ((tempbf = br.readLine()) != null) {
html.append(tempbf + "\n");
}
代碼 大概就是這樣的
// 默認的client類。
HttpClient client = new DefaultHttpClient();
// 設置為get取連接的方式.
HttpGet get = new HttpGet(url);
// 得到返回的response.
HttpResponse response = client.execute(get);
// 得到返回的client裡面的實體對象信息.
HttpEntity entity = response.getEntity();
if (entity != null) {
System.out.println( entity.getContentEncoding());
System.out.println( entity.getContentType());
// 得到返回的主體內容.
InputStream instream = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(instream, encoding));
System.out.println(reader.readLine());
// EntityUtils 處理HttpEntity的工具類
// System.out.println(EntityUtils.toString(entity));
}
// 關閉連接.
client.getConnectionManager().shutdown();