简体   繁体   中英

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. There are only $_GET and $_POST and $_REQUEST which also just holds GET , POST and cookies .

There is no such thing as "PUT parameters". The HTTP request that is sent with PUT method contains request body. This body can be read from php://input stream.

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

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 />';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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