0

I am using a php framework - Yii2 for developing an API where I want to handle 4 types requests : GET, POST, PUT and DELETE. Here I can catch the parameters in GET and POST, but I can't access the parameters in PUT and DELETE methods.

I had found some codes after a wide search. But it didn't work fine for me. Sample code are:

Sample 1 :

$putdatafp = fopen("php://input", "r");
$putfp = fopen('php://input', 'r');
$putdata = '';
while($data = fread($putfp, 1024))
    $putdata .= $data;
fclose($putfp);

var_dump($putdata);

Sample 2:

parse_str(file_get_contents("php://input"),$put_vars);
var_dump($put_vars);

But these two returns string datas. How can I parse the PUT and DELETE parameters into an array.

Any help would be greatly appreciated

Sherin Jose
  • 2,508
  • 3
  • 18
  • 39
  • Maybe this will help you: http://stackoverflow.com/questions/2081894/handling-put-delete-arguments-in-php – okonek83 Feb 26 '17 at 12:15
  • Yea thanks, Also I had changed the `Content-Type` header to `application/x-www-form-urlencoded`. Now its working :) – Sherin Jose Feb 26 '17 at 12:30
  • 1
    Possible duplicate of [Handling PUT/DELETE arguments in PHP](http://stackoverflow.com/questions/2081894/handling-put-delete-arguments-in-php) – Samuel Hapak Feb 26 '17 at 17:35

0 Answers0