请求网络中GET和POST的学习理解
2016-03-06 17:43
441 查看
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();
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的理解学习
- 基于Netty4的HttpServer和HttpClient的简单实现
- 苹果iphone4s完美越狱后破解4g网络方法
- [总结]有上下界的网络流
- Android Http请求方法汇总
- WebSocket之获取HttpSession
- TCP的四种定时器简单记录
- HttpClient和HttpURLConnection的区别
- CNN(卷积神经网络)、RNN(循环神经网络)、DNN(深度神经网络)的内部网络结构有什么区别?
- 【网络流24题】圆桌问题
- TCP/IP Note4
- Linux 网络编程 基本函数
- UNIX网络编程——网络I/O模型
- java高级---线程、网络、文件、流、序列化等代码示例
- TCP/IP Note3
- 搭建HTTP Live Streaming直播系统
- 【独立开发者er Cocos2d-x实战 014】Cocos2dx中的TestCPP运行Box2dTest
- TCP/IP Note2
- TCP/IP Note1
- 基于人工神经网络的五子棋博弈(转载请注明出处!)