理解 HTTP POST 请求/响应过程
Understanding the HTTP POST request / response process
我一直在试图彻底理解HTTP POST请求/响应过程,虽然google上有很多资源,但none明明白白地给我答案我之后。
示例场景:
我有一个搜索表单,我输入一些查询并提出请求。然后我被重定向到搜索结果页面。
谁能解释一下这个过程;特别是,我对重定向最感兴趣。
这就是我认为的情况:
POST request containing query
|
v
Server receives request.
|
V
Server sends back response containing the page that the client should subsequently request.
|
V
Client receives response and requests page indicated in the response.
|
V
Server receives request and sends back requested page.
|
V
Client renders page.
事情就是这样。有关此模式的解释,请参阅 Post/Redirect/Get on Wikipedia。
客户端执行POST请求:
Client -> Server: POST / HTTP/1.1 (+payload)
Server -> Client: HTTP/1.1 302 See other (+location header +payload)
现在客户端看到 302 并对 location
header:
标识的资源执行附加请求
Client -> Server: GET $location HTTP/1.1
Server -> Client: HTTP/1.1 200 OK (+payload)
我一直在试图彻底理解HTTP POST请求/响应过程,虽然google上有很多资源,但none明明白白地给我答案我之后。
示例场景:
我有一个搜索表单,我输入一些查询并提出请求。然后我被重定向到搜索结果页面。
谁能解释一下这个过程;特别是,我对重定向最感兴趣。
这就是我认为的情况:
POST request containing query
|
v
Server receives request.
|
V
Server sends back response containing the page that the client should subsequently request.
|
V
Client receives response and requests page indicated in the response.
|
V
Server receives request and sends back requested page.
|
V
Client renders page.
事情就是这样。有关此模式的解释,请参阅 Post/Redirect/Get on Wikipedia。
客户端执行POST请求:
Client -> Server: POST / HTTP/1.1 (+payload)
Server -> Client: HTTP/1.1 302 See other (+location header +payload)
现在客户端看到 302 并对 location
header:
Client -> Server: GET $location HTTP/1.1
Server -> Client: HTTP/1.1 200 OK (+payload)