首页 > 移动平台 > 详细

android http 通信(httpclient 实现)

时间:2016-02-10 19:54:17      阅读:282      评论:0      收藏:0      [点我收藏+]

1.httpclient get 方式

  HttpGet httpGet = new HttpGet(url);
  HttpClient client = new DefaultHttpClient();
  HttpResponse response=client.execute(httpGet);
  if(response.getStatusLine().getStatusCode() == HttpStatus.SC_Ok){
    String content = EntityUtils.toString(response.getEntity);
  }

2.httpclient post 方式

HttpPost post= new HttpPost(url);
HttpClient client = new DefaultHttpClient();

ArrayList<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("name",name));
list.add(new BasicNameValuePair("age",age));

post.setEntity(new UrlEncodedFormEntity(list));

HttpResponse response=client.execute(post);
if(response.getStatusLine().getStatusCode() == HttpStatus.SC_Ok){
 String content = EntityUtils.toString(response.getEntity);
}

 

android http 通信(httpclient 实现)

原文:http://www.cnblogs.com/luoxiaolei/p/5186076.html

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