简体   繁体   English

将HTTP POST重定向到GET时,POST正文会发生什么?

[英]When an HTTP POST is redirected to GET, what happens to the body of the POST?

As per my previous question , I need to redirect an HTTP POST request to a different server. 根据我之前的问题 ,我需要将HTTP POST请求重定向到其他服务器。 I believe this can be done using HTTP response headers from php, but I understand the POST request will become a GET request. 我相信可以使用php的HTTP响应标头完成此操作,但我知道POST请求将成为GET请求。 My question is what happens to the body of the HTTP request? 我的问题是HTTP请求的主体会发生什么? is it discarded, or will it be converted to be part of the GET request's query url? 是将其丢弃还是将其转换为GET请求的查询网址的一部分?

ie if a POST is made to http://mysite.com/handler.php and I redirect to http://othersite.com/handler.php will it automatically become http://othersite.com/handler.php?param1=hello&param2=world 即,如果对http://mysite.com/handler.php进行POST,而我重定向到http://othersite.com/handler.php它将自动变为http://othersite.com/handler.php?param1=hello&param2=world

The POST data vanishes. POST数据消失。 Unless the redirecting script takes steps to push the POST data into the GET's URL or into a cookie, the data's dead and gone. 除非重定向脚本采取了将POST数据推送到GET的URL或cookie中的步骤,否则数据将失效。

This is somewhat by design. 这是设计使然。 Most browsers limit the length of a URL, and POSTs have effectively no limit to the size of the data being POSTed, so you wouldn't want that 500megabyte file you just uploaded appended to the GET url's query line. 大多数浏览器都会限制URL的长度,而POST实际上没有限制要发布的数据的大小,因此您不希望刚上传的500 MB文件附加到GET URL的查询行中。

If you are using CURL to redirect such a request, it is regarded as a distinct, new HTTP request that is not related to the original one at all. 如果您使用CURL重定向这样的请求,则它将被视为与原始请求完全不相关的独特的新HTTP请求。 The only data that gets passed along is that which you explicitly pass in the query string. 传递的唯一数据是您在查询字符串中显式传递的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM