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

android http 通信(httpclient 实现)

时间:2016-02-10 19:54:23      阅读:214      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!