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

2022-01-04 00:00:00 http post redirect get php

根据我之前的问题,我需要将 HTTP POST 请求重定向到另一个服务器.我相信这可以使用来自 php 的 HTTP 响应头来完成,但我知道 POST 请求将成为 GET 请求.我的问题是 HTTP 请求的正文会发生什么?它是被丢弃了,还是会被转换为 GET 请求的查询 url 的一部分?

As per my previous question, I need to redirect an HTTP POST request to a different server. I believe this can be done using HTTP response headers from php, but I understand the POST request will become a GET request. My question is what happens to the body of the HTTP request? is it discarded, or will it be converted to be part of the GET request's query url?

即如果对 http://mysite.com/handler.php 进行 POST 并且我重定向到 http://othersite.com/handler.php 它将自动变为http://othersite.com/handler.php?param1=hello&param2=world

i.e. 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

推荐答案

POST 数据消失.除非重定向脚本采取措施将 POST 数据推送到 GET 的 URL 或 cookie 中,否则数据将消失不见.

The POST data vanishes. 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.

这在某种程度上是设计使然.大多数浏览器都会限制 URL 的长度,而 POST 对所发布数据的大小实际上没有限制,因此您不希望将刚刚上传的 500 兆字节文件附加到 GET url 的查询行.

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.

相关文章