2015-08-08 216 views
0

我一直在尝试彻底理解HTTP POST请求/响应过程,尽管在google上有很多资源,但没有一个明确地给我答案。了解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. 

回答

1

这正是发生了什么。有关此模式的说明,请参见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) 

可以使用Fiddler或用于检查HTTP流量的Charles

+0

真棒,感谢您的确认 – Robbo