源地址:http://www.eoeandroid.com/thread-13873-1-1.html
//取得取得默认的HttpClient实例
DefaultHttpClient httpClient = new DefaultHttpClient();//创建HttpGet实例
HttpGet request = new HttpGet("http://www.baidu.com?url=http://wap.sohu.com/");
try
{
//连接服务器
HttpResponse response =httpClient.execute(request);
//读取所有头数据
Header[] header = response.getAllHeaders();
HashMap<String, String> hm = new HashMap<String, String>();
for (int i = 0; i < header.length; i++)
{
hm.put(header[i].getName(), header[i].getValue());
}
//取得数据记录
HttpEntity entity = response.getEntity();
//取得数据记录内容
InputStream is = entity.getContent();
//显示数据记录内容
BufferedReader in = new BufferedReader(new InputStreamReader(is));
String str = "";//in.readLine();
StringBuffer s = new StringBuffer("");
while((str = in.readLine()) != null){
s.append(str);
}
//释放连接
httpClient.getConnectionManager().shutdown();
}
catch (ClientProtocolException e)
{
e.printStackTrace();
Toast.makeText(getBaseContext(),"ClientProtocolException",Toast.LENGTH_SHORT).show();
}
catch (IOException e)
{
e.printStackTrace();
Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_SHORT).show();
}
}