php5rp_ng
php5rp_ng copied to clipboard
PUT/DELETE don't work
I changed the PUT code locally and implemented it this way:
http://www.lornajane.net/posts/2009/putting-data-fields-with-php-curl
To implement DELETE you can find code in following article:
http://developer.sugarcrm.com/2013/08/30/doing-put-and-delete-with-curl-in-php/
thanks. i will take a look at the urls and fix this.
+1 that! I too am finding DELETE doesn't work. I've tried implementing suggestions above, but no dice.
I had to fix this locally too. This was my journey:
On the original code inside this repository we have:
case 'PUT':
// Set the request method.
$this->setCurlOption(CURLOPT_UPLOAD, 1);
// PUT data comes in on the stdin stream.
$putData = fopen($inputStream, 'r');
$this->setCurlOption(CURLOPT_READDATA, $putData);
// TODO: set CURLOPT_INFILESIZE to the value of Content-Length.
break;
This is the code that doesn't work. "CURLOPT_READDATA" doesn't appear in this documentation http://php.net/manual/es/function.curl-setopt.php so I really don't know what the author meant by that? The code gives me the following error:
curl_setopt(): cannot represent a stream of type Input as a STDIO FILE*
Maybe the problem is that it was expecting me to push a file in the PUT request but instead I'm pushing a json object (perfectly valid PUT request), but I really have no idea actually.
When looking at other examples on how to do a PUT curl (like in the link referenced by @lievenjanssen and also as explained by this comment in the docs: http://php.net/manual/es/function.curl-setopt.php#96056) we can see that they use "CURLOPT_POSTFIELDS" to define the data that should be pushed in the PUT curl request. In fact, after having it working and doing some reworks I realized I was writing the same code that the author already has in the "case 'POST':"
Indeed, I deleted the whole "case 'PUT'" and just added it to the POST case. I also added the case 'DELETE', like so:
case 'POST':
case 'PATCH':
case 'PUT':
case 'DELETE':
$data = '';
if (isset($options['data'])) {
$data = $options['data'];
}
else {
if (!isset($HTTP_RAW_POST_DATA)) {
$HTTP_RAW_POST_DATA = file_get_contents($inputStream);
}
$data = $HTTP_RAW_POST_DATA;
}
$this->setCurlOption(CURLOPT_POSTFIELDS, $data);
break;
Which works fine for my use-case (doing POST and PUT with jsons)