码迷,mamicode.com
首页 > Web开发 > 详细

HttpClient的get用法

时间:2016-04-14 16:03:38      阅读:161      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!