HTTP Post请求过程详解

时间:2023-03-08 23:51:19
HTTP Post请求过程详解

摘要:

HTTP(HyperText Transfer Protocol),超文本传输协议,是一个客户端和服务器端请求和应答的标准(TCP),客户端是终端用户,服务器端是网站。

HTTP是基于Socket之上的协议。HTTP POST是上传数据到服务器。

调用地址:  http://127.0.0.1:8080/login.html

请求报文:

1
2
3
4
5
6
7
8
POST /web/login.html HTTP/1.1
User-Agent: MyBrowser
Host: 127.0.0.1:8080
Proxy-Connection: Keep-Alive
Content-Length: 49
Content-Type: application/x-www-form-urlencoded
username=username&password=password&type=1&type=2

POST : post请求

/web/login.html  : 站点路径

HTTP/1.1 : 协议及版本

Content-Length: 请求内容长度。

Content-Type: 请求内容类型,这里为application/x-www-form-urlencoded:标准的编码格式,数据被编码为名称/值对。

username=username&password=password&type=1&type=2: 请求的内容,按Content-Type编码。

响应报文:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=BAAE42AF1B4F2D3540D6EC8490A5FB9F; Path=/web
Content-Type: text/html;charset=UTF-8
Content-Length: 314
Date: Thu, 05 Feb 2015 07:39:09 GMT
<!DOCTYPE>
<html>
<head>
<base href="http://127.0.0.1:8080/web/">
<title>登录</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>
<h1>HelloWorld!!!</h1>
</body>
</html>

HTTP/1.1 : 协议及版本

200:响应状态码

Server:服务器类型

Set-Cookie:浏览器Cookie

Content-Type:响应内容类型

Content-Length:响应内容长度

Date:响应时间