网站开发要知道的事——关于post和get的区别
2013-07-04 16:55
363 查看
最简单的理解:
GET的方式是把参数数据在地址栏中明文的形式发送,可以在浏览器的地址栏中输入网址的方式直接访问网页:例如:http://localhost/test.html?id=123;其中?id=123就是get数据,整个uri长度限制在1024个字。
POST则不能直接在浏览器中输入地址访问,而是把数据放到http请求中,一般采用form表单隐藏域提交。浏览器地址栏不能够看到参数数据。例如:同样传递id=123,地址栏只能看到http://localhost/test.html,参数数据看不到。想看到post数据可以用一些抓包工具,如Wireshark等。
以下是对这两个方式区别的具体概括:
1. GET是从服务器上获取数据,POST是要求被请求服务器接受附在请求后面的数据,常用于提交表单。(例如与银行交互时提交订单支付信息)
2. GET是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到。POST是通过HTTPPOST机制,将表单内各个字段与其内容放置在HTML HEADER内一起传送到ACTION属性所指的URL地址。用户看不到这个过程。
3. 对于GET方式,服务器端用Request.QueryString获取变量的值,对于POST方式,服务器端用Request.Form获取提交的数据。
4. GET传送的数据量较小,不能大于2KB。POST传送的数据量较大,一般被默认为不受限制。但理论上,IIS4中最大量为80KB,IIS5中为100KB。
5. GET安全性非常低,POST安全性较高。但是执行效率却比POST方法好。
建议:
1、GET方式的安全性较POST方式要差些,包含机密信息的话,建议用POST数据提交方式;
2、在做数据查询时,建议用GET方式;而在做数据添加、修改或删除时,建议用POST方式;
关于接口调用的GET和POST方法
以下是C#的以GET方式调用接口:
以下是C#的以POST方式调用接口:
GET的方式是把参数数据在地址栏中明文的形式发送,可以在浏览器的地址栏中输入网址的方式直接访问网页:例如:http://localhost/test.html?id=123;其中?id=123就是get数据,整个uri长度限制在1024个字。
POST则不能直接在浏览器中输入地址访问,而是把数据放到http请求中,一般采用form表单隐藏域提交。浏览器地址栏不能够看到参数数据。例如:同样传递id=123,地址栏只能看到http://localhost/test.html,参数数据看不到。想看到post数据可以用一些抓包工具,如Wireshark等。
以下是对这两个方式区别的具体概括:
1. GET是从服务器上获取数据,POST是要求被请求服务器接受附在请求后面的数据,常用于提交表单。(例如与银行交互时提交订单支付信息)
2. GET是把参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看到。POST是通过HTTPPOST机制,将表单内各个字段与其内容放置在HTML HEADER内一起传送到ACTION属性所指的URL地址。用户看不到这个过程。
3. 对于GET方式,服务器端用Request.QueryString获取变量的值,对于POST方式,服务器端用Request.Form获取提交的数据。
4. GET传送的数据量较小,不能大于2KB。POST传送的数据量较大,一般被默认为不受限制。但理论上,IIS4中最大量为80KB,IIS5中为100KB。
5. GET安全性非常低,POST安全性较高。但是执行效率却比POST方法好。
建议:
1、GET方式的安全性较POST方式要差些,包含机密信息的话,建议用POST数据提交方式;
2、在做数据查询时,建议用GET方式;而在做数据添加、修改或删除时,建议用POST方式;
关于接口调用的GET和POST方法
以下是C#的以GET方式调用接口:
public static string SendAndGetInterfaceData(string strInterfaceUrl) { string strBackData = ""; //返回数据 HttpWebRequest req; HttpWebResponse res = null; Stream requestStream; StreamReader sr = null; //----------------------------------------- //往接口发送数据 //----------------------------------------- req = (HttpWebRequest)WebRequest.Create(strInterfaceUrl); req.ReadWriteTimeout = 6000; //设置超时 req.Method = "GET"; req.ContentType = "application/x-www-form-urlencoded"; try { //------------------------------------------ //接收接口数据 //------------------------------------------ res = (HttpWebResponse)req.GetResponse(); sr = new StreamReader(res.GetResponseStream(), Encoding.GetEncoding("utf-8")); strBackData = sr.ReadToEnd(); } catch (WebException ex) { //strBackData = ex.Message; strBackData = ""; throw ex; } finally { if (sr != null) sr.Close(); if (res != null) res.Close(); } return strBackData; }
以下是C#的以POST方式调用接口:
public static string SendAndGetInterfaceDataByPost(string strInterfaceUrl, string strDataXml) { string strBackData; //返回数据 byte[] byArrRequest; HttpWebRequest req; HttpWebResponse res = null; Stream requestStream; StreamReader sr = null; DataTable dt; Encoding gb2312 = Encoding.GetEncoding("utf-8"); //----------------------------------------- //往接口发送数据 //----------------------------------------- req = (HttpWebRequest)WebRequest.Create(strInterfaceUrl + "?" + strDataXml); req.ReadWriteTimeout = 6000; //设置超时 byArrRequest = gb2312.GetBytes(strDataXml); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = byArrRequest.Length; try { requestStream = req.GetRequestStream(); requestStream.Write(byArrRequest, 0, byArrRequest.Length); requestStream.Close(); //------------------------------------------ //接收接口数据 //------------------------------------------ res = (HttpWebResponse)req.GetResponse(); sr = new StreamReader(res.GetResponseStream(), gb2312); strBackData = sr.ReadToEnd(); } catch (WebException ex) { strBackData = ex.Message; //strBackData = ""; throw ex; } finally { if (sr != null) sr.Close(); if (res != null) res.Close(); } return strBackData; }
相关文章推荐
- 关于web开发中get与post方法之间的区别
- 关于最近学习的自动登录网站技术以及post get请求
- Servlet(6)Servlet三种开发方式之继承GenericServlet、HttpServlet及get和post提交表单方式的区别
- 浅谈关于GET和POST两种请求的区别
- 力所能及之关于用JavaScript方式写ajax,post与get提交的注意区别
- 【开发技术】Get请求和Post请求区别
- 【JSP开发】GET与POST提交区别
- Java Web开发8__HTTP GET请求、POST请求的区别, 重写 service() 方法
- HTTP协议的特点,关于HTTP请求GET和POST的区别
- GET和POST的区别及get和post关于请求的编解码的问题
- 关于get和post请求的区别
- 关于get与post传递参数容量大小限制区别以及curl函数与file_get_contents的区别(面试)
- 关于Form的method属性get和post是有区别滴
- 关于Http协议的get方法和post方法的区别和用法
- 关于HTTP 协议的特点,以及网络请求GET 和 POST 的区别?
- 【前端HTML】关于提交方式post和get区别(代码案例)
- 关于 GET和POST请求的区别
- Java Web开发 之小张老师总结GET和POST区别
- web 开发常见问题--GET POST 区别
- webform开发中get与post的区别