Http Get 和 Post
2024-04-14 15:14:40
最近工作中要求由客户端向服务端发送数据,采用的是Http协议,即Get和Post请求操作。通常情况下,Get用于请求数据,Post用于上传数据更新服务器。Get请求应该是安全的和等幂的。
在提交表单时,如果将表单的Method属性设置为get,那么表单提交采用get方式提交数据发送请求,使用get方式,表单中的信息是以Key=Value&Key=Value的方式连接在Url之后。采用ASP.NET MVC 3举例验证:
View:
@{ViewBag.Title = "Http Get 与 Post学习分析";
}<h2>Http Get 与 Post学习分析</h2>
@using (Html.BeginForm("Add", "Student", FormMethod.Get))
{<table><tr><td>UserName:</td><td><input type="text" name="userName" id="userName" /></td><td>Password:</td><td><input type="text" name="passWord" id="password" /></td><td><input type="submit" value="Submit" /></td></tr></table>
}
Controller:
public class StudentController : Controller{public ActionResult Add(string userName, string passWord){string information = "UserName: " + userName + "Password: " + passWord;return View();}}
初始运行:
UserName、Password文本框分别输入:123456,单击Submit按钮:
该get请求Headers:
Request URL:http://localhost:4126/?userName=123456&passWord=123456
Request Method:GET
Status Code:200 OK
Request Headers:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:zh-CN,zh;q=0.8
Connection:keep-alive
Host:localhost:4126
Referer:http://localhost:4126/
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19
Query String Parameters,连接到Url之后
userName:123456
passWord:123456
Response Headers:
Cache-Control:private
Connection:Close
Content-Length:408
Content-Type:text/html; charset=utf-8
Date:Sun, 20 May 2012 16:11:00 GMT
Server:ASP.NET Development Server/10.0.0.0
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:3.0
由于get方式,数据存放在Url中的,采用明文方式,所以安全性不高,并且get方式最多只能传输1024个字节
对于Post方式,表单中的数据时存放在http请求的Header中的,不可见。
View:
@{ViewBag.Title = "Http Get 与 Post学习分析";
}<h2>Http Get 与 Post学习分析</h2>
@using (Html.BeginForm("Add", "Student", FormMethod.Post))
{<table><tr><td>UserName:</td><td><input type="text" name="userName" id="userName" /></td><td>Password:</td><td><input type="text" name="passWord" id="password" /></td><td><input type="submit" value="Submit" /></td></tr></table>
}
Controller:
public class StudentController : Controller{public ActionResult Add(){return View();}[HttpPost]public ActionResult Add(string userName, string passWord){string information = "UserName: " + userName + "Password: " + passWord;return View();}}
初始运行:
UserName、Password文本框分别输入:123456,单击Submit按钮:
下面来观察http Header:
Request URL:http://localhost:4126/
Request Method:POST
Status Code:200 OK
Request Headers:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:zh-CN,zh;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:31
Content-Type:application/x-www-form-urlencoded
Host:localhost:4126
Origin:http://localhost:4126
Referer:http://localhost:4126/
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.162 Safari/535.19
Form Data:post方式数据存放容器
userName:123456
passWord:123456
Response Headers:
Cache-Control:private
Connection:Close
Content-Length:409
Content-Type:text/html; charset=utf-8
Date:Sun, 20 May 2012 16:27:55 GMT
Server:ASP.NET Development Server/10.0.0.0
X-AspNet-Version:4.0.30319
X-AspNetMvc-Version:3.0
由此可见:Post安全性高,传输数据量大。以此作为笔记,如有不足之处,请指正。
转载于:https://www.cnblogs.com/PerfectSoft/archive/2012/05/21/2511043.html
最新文章
- 联想计算机农村,农村的联想
- AndroidWear开发之HelloWorld篇
- Boost.MultiIndex 复合键的例子
- Codeforces Round #620 (Div. 2) E. 1-Trees and Queries 思维 + LCA
- 开源软件生态_基础,亮点和建立成功的开源生态系统
- Mysql 数据库语句常用总结
- 重做《机房收费系统》——概要设计(UI)
- FFmpeg源代码简单分析:av_write_frame()
- 【镜像更新】Windows Server 2016 数据中心版
- axure 7.0 注册码
- n维椭球体积公式_初中物理公式总结(表格整理版)
- html在div中数字时钟,在JS+CSS中如何实现滚动数字时钟
- 浏览器主页被劫持成360导航
- 小学到大学各类英语教学视频(一)
- 太阳直射点纬度计算公式_高中地理:正午太阳高度公式的应用
- hillin:浮木漂流
- Python 绘画excel分组柱状图(懒人学习)
- input表单所有属性【web前端】
- 智能媒体管理产品文档转换/预览功能介绍(1)---Cloud Native架构
- reply-code=503, reply-text=COMMAND_INVALID - unknown exchange type 'x-delayed-message'
热门文章
- mysql 2进制 安装_mysql二进制安装
- php限制ip访问次数 并发_[转]nginx限制某个IP同一时间段的访问次数
- 计算机组成原理试卷五套,计算机组成原理(五套试题)
- 怎么选择网管型和非网管型交换机
- python3字典升序排序_Python(32)常用指引:排序指南
- Python+Selenium+PO模型实现自动化测试
- 计算机网络是由一组结点组成吗,分布式数据库系统是由一组数据组成的,这组数据分布在计算机网络的不同计算机上,网络中的每个结点_考题宝...
- python预测随机数据_随机森林预测
- postman cookie设置_接口鉴权之cookie,session和token
- python爬取网页公开数据_如何用Python爬取网页数据