首页 > Web开发 > 详细

httpClient中的get和post请求

时间:2016-02-25 13:36:32      阅读:164      评论:0      收藏:0      [点我收藏+]

HttpClient,get请求的流程:
//创建HttpClient对象
HttpClient client=new DefaultHttpClient();
//创建HttpGet对象并传入参数url,发送get请求
String url="http://192.......";
HttpGet get=new HttpGet(url);
//处理响应
HttpResponse resp=client.execute(get):

 

HttpClient,post请求的流程:

//描述一个客户端
HttpClient client=new DefaultHttpClient();
String url="http://192.......";
//新建Httppost,并传入url
HttpPost post=new HttpPost(url);
//设置请求参数
List<NameValuePair>pairs=new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("name","张三“));
//描述实体
HttpEntity entity=new UrlEncodedFormEntity(pairs,"utf-8");
//添加请求消息头
post.setEntity(entity);
post.setHeader("Content-Type","application/x-www-form-urlencoder");
HttpResponse resp=client.execute(post);

httpClient中的get和post请求

原文:http://www.cnblogs.com/gentspy/p/5216631.html

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