现在的位置: 首页 > 综合 > 正文

使用HttpClient一般步骤

2018年01月31日 ⁄ 综合 ⁄ 共 496字 ⁄ 字号 评论关闭
HttpResponse httpResponse=null;
HttpEntity httpEntity=null;
InputStream inputStream=null;

//生成一个请求对象
HttpGet httpGet=new HttpGet("ww.baidu.com");
//生成一个Http客户端对象
HttpClient httpClient=new DefaultHttpClient();

try{
  //使用Http客户端发送请求对象
  httpResponse=httpClient.execute(httpGet);
  //获取响应内容
  httpEntity=httpResponse.getEntity();
  BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
	
  String result="";
  String line="";
  while(line=reader.readLine()!=null){
     result+=line;
  }

}
catch(Exception e){
   e.printStrackTrace();
}

抱歉!评论已关闭.