我一直在努力彻底了解HTTP POST请求/响应流程,虽然谷歌上有很多资源,但没有人明白地给我答案。
示例场景:
我有一个搜索表单,我输入一些查询并发出请求。然后我被重定向到搜索结果页面。
有人可以解释这个过程;特别是,我对重定向最感兴趣。
这就是我的想法:
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.
答案 0 :(得分:2)
确切地说会发生什么。有关此模式的说明,请参阅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
标头标识的资源执行额外请求:
Client -> Server: GET $location HTTP/1.1
Server -> Client: HTTP/1.1 200 OK (+payload)