首页 > Web开发 > 详细

HttpClient的get用法

时间:2016-04-14 16:03:32      阅读:190      评论:0      收藏:0      [点我收藏+]

httpClient(执行时都需要放进线程中):

try {

String path="路径";

HttpClient httpClient=new DefaultHttpClient();
HttpGet httpGet=new HttpGet(path);

HttpResponse response = httpClient.execute(httpGet);
int code = response.getStatusLine().getStatusCode();


if(code==200){

  InputStream is = response.getEntity().getContent();
  ByteArrayOutputStream bos=new ByteArrayOutputStream();
  int len;
  byte[] by=new byte[1024];
  while((len=is.read(by))!=-1){
    bos.write(by,0,len);
  }
  String json=bos.toString();

     //解析gson字符串
  Gson gson=new Gson();
  History history = gson.fromJson(json, History.class);
  List<ArrayHis> his=history.array;

  return his;
}
} catch (Exception e) {

e.printStackTrace();
}

HttpClient的get用法

原文:http://www.cnblogs.com/coins1/p/5391221.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!