Jo Smo
Jo Smo

Reputation: 7169

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.

Upvotes: 0

Views: 97

Answers (2)

Jo Smo
Jo Smo

Reputation: 7169

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

Upvotes: 0

Bartosz Zasada
Bartosz Zasada

Reputation: 3900

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

Upvotes: 2

Related Questions