GET与POST请求方法
1.请求参数的存放位置
GET:请求资源路径后拼接
POST:存放在请求实体
2.安全性
3,是否适合传递中文
GET: 不适合
POST:较适合
4,是否适合大数据提交
POST:适合
*发送GET请求
//创建HttpClient对象
HttpClient client=new DefaultHttpClient();
//创建GET请求对象
String url=“http://172.xx.:8080/findFlights.jsp”;
HttpGet get=new HttpGet(url);
//执行请求client对象的excute方法中传入get参数
HttpResponce resp=client.excute(get);
//解析响应
resp.getStatusLine();//从resp中得到状态行
resp.getAllHeaders();
resp.getEntiry();
.。。。。。。。。。。。。。。。。。。。。
*发送POST请求
//创建HttpClient
//创建HttpPost
HttpPost post=new HttpPost(url);
//设置HttpPost请求参数及消息头
POST.setHeader(“ Content-type”,"application/x-www-form-urlencoded");
List<NameValuePair>list=new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("data","2015-12-22"));
list.add(new BasicNameValuePair("number","No.10011"));
HttpEntiry entity=new UrlEncodedFormEntity(list,"utf-8");
post.sentEntity(entity);
//client调用execute执行返回resp
HttpResponse resp=client.execute();
//解析
resp.getStatusLine();
resp.getAllHeaders();
resp.getEntity();
原文:http://www.cnblogs.com/gentspy/p/5248037.html