Http Request的一些理解

来源:互联网 发布:vc界面编程经典实例 编辑:程序博客网 时间:2024/06/08 09:14
使用Fiddler抓一下HTTP的请求和响应
1、一个典型的Request:
POST http://localhost:8080/Servlet02/login HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 28
Cache-Control: max-age=0
Origin: http://localhost:8080
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Referer: http://localhost:8080/Servlet02/login.html
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.8

userName=Shelley&userPwd=123
分析上面的request:
2、Request请求的部分:

请求首行(必须有):POST http://localhost:8080/Servlet02/login HTTP/1.1

         |-- 方法:GET、POST、HEAD、DELETE、PUT、TRACE、OPTIONS
         |-- 请求 URL
         |-- 协议名称/版本号

请求头(一般来说都有):
Host: localhost:8080                    //要访问的服务器 : 服务器名:端口号
                       Connection: keep-alive               // 保持连接,是 HTTP/1.1 版本特有,1.0版本每次都需要建立一个连接,1.1 是对1.0的优化
                       Content-Length: 28                     // 指请求正文的长度(byte)
                       User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36                                                       //客户端的信息
Content-Type: application/x-www-form-urlencoded     // 请求正文类型
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8   //能接收的响应正文类型:MIME
Referer: http://localhost:8080/Servlet02/login.html        //指明请求由哪个路径发起(来源统计、防止盗链)
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.8

请求空行:分隔请求头和请求正文的作用。因为每次请求的请求头的数量可能不一样,所以需要这样空行来标识请求头结束

请求正文:只有POST请求才会有请求正文。如果是GET方式,会把参数放到查询字符串去。
userName=Shelley&userPwd=123 

一个典型的POST请求:


一个典型的GET请求:

GET跟POST的区别:GET的参数会作为URL的Q ueryString提交,而POST的参数会作为请求正文提交

原创粉丝点击