简体   繁体   English

如何从当前HTTP请求的正文中获取所有HTTP PUT“参数”的列表?

[英]How to get a list of all HTTP PUT “parameters” from the body of the current HTTP request?

I tried with $_PUT , but looks like that this variable doesn't exist. 我尝试使用$_PUT ,但是看起来该变量不存在。 There are only $_GET and $_POST and $_REQUEST which also just holds GET , POST and cookies . 只有$_GET$_POST以及$_REQUEST ,它们也仅包含GETPOSTcookies

There is no such thing as "PUT parameters". 没有“ PUT参数”之类的东西。 The HTTP request that is sent with PUT method contains request body. 使用PUT方法发送的HTTP请求包含请求正文。 This body can be read from php://input stream. 可以从php://input流读取此主体。

I found a blog post that describes how the request body can be parsed, if PUT method is used to send POST-like parameters: http://www.chlab.ch/blog/archives/webdevelopment/manually-parse-raw-http-data-php 我发现了一篇博客文章,描述了如果使用PUT方法发送类似POST的参数,则如何解析请求正文: http : //www.chlab.ch/blog/archives/webdevelopment/manually-parse-raw-http -数据-PHP

I ended up with this: 我结束了这个:

if($_SERVER['REQUEST_METHOD'] == 'PUT') {
    echo 'This is a HTTP PUT request.<br />';
    parse_str(file_get_contents('php://input'), $put);
    echo $put['user'] . '<br /><br />';
}

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

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