4

Is there any way I can access data that was sent via HTTP PUT method other than $putdata = fopen("php://input", "r");?

I have never worked with PUT and DELETE methods and $putdata = fopen("php://input", "r"); seems a bit sketchy. Will it work everywhere is a specific server/php.ini configuration required?

I know that I can get the request method from $_SERVER['REQUEST_METHOD'];

But will the data be in $_REQUEST, if yes then what php://input is about? And how do I access data that was sent via DELETE?

4

1 回答 1

3

不,您需要手动解析请求。$_REQUEST仅包含来自GETPOST请求的数据;对于其他一切,您都靠自己。

如果你的 HTTP 请求有Content-Type: application/x-www-form-urlencoded,你可以很容易地将它解析回一个变量数组,parse_str如下所示:

parse_str(file_get_contents('php://input'), $vars);
print_r($vars);

您可以将此内容类型与任何 HTTP 方法一起使用,没有标准强加的限制。

于 2013-04-30T21:22:37.880 回答