使用PHP的HTTP PUT,DELETE和I / O流 [英] HTTP PUT, DELETE and I/O streams with PHP
问题描述
有什么方法可以访问通过HTTP PUT方法发送的数据,而不是 $ putdata = fopen(php:// input,r);
?
Is there any way I can access data that was sent via HTTP PUT method other than $putdata = fopen("php://input", "r");
?
我从未使用 PUT
和 DELETE
方法和 $ putdata = fopen(php:// input,r);
似乎有点粗略。是否需要特定的server / php.ini配置?
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?
我知道我可以从 $ _ SERVER ['获取请求方法REQUEST_METHOD'];
但数据是否在 $ _ REQUEST
中,如果是然后 php://输入
是关于什么的?
如何访问通过 DELETE
发送的数据?
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
?
推荐答案
不,您需要手动解析请求。 $ _ REQUEST
仅包含来自 GET
和 POST
请求的数据;对于你自己的其他一切。
No, you will need to parse the request manually. $_REQUEST
only contains data coming from GET
and POST
requests; for everything else you are on your own.
如果你的HTTP请求有 Content-Type:application / x-www-form-urlencoded
,您可以使用 <轻松地将其解析为变量数组code> parse_str 像这样:
If your HTTP request has Content-Type: application/x-www-form-urlencoded
, you can parse it back into a variables array very easily with parse_str
like this:
parse_str(file_get_contents('php://input'), $vars);
print_r($vars);
您可以将此内容类型与任何HTTP方法一起使用,没有标准限制。
You can use this content type with any HTTP method, there is no standard-imposed limitation.
这篇关于使用PHP的HTTP PUT,DELETE和I / O流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!