Hi
Thanks for your reply.
Yes, using your method I can now see some output at least…I have two queries:
Following is the code I am using to make a REST request…The $data variable contains the data in array() format…
For example:
$data = array(
‘a’ => 1,
‘b’ => 2
);
$ch = curl_init();
switch($methodName){
case 'PUT':
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-HTTP-Method-Override: PUT') );
break;
case 'DELETE':
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-HTTP-Method-Override: DELETE') );
break;
}
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set curl to return the data instead of printing it to the browser.
$data = curl_exec($ch);
curl_close($ch);
Question 1) For both PUT and DELETE, When I use:
echo file_get_contents("php://input");
I get the output:
------------------------------42c0c61e0e16
Content-Disposition: form-data; name="1"
Array
------------------------------42c0c61e0e16
Content-Disposition: form-data; name="2"
Array
------------------------------42c0c61e0e16--
and when I use:
parse_str(file_get_contents("php://input"),$post_vars);
print_r($post_vars);
I get this output:
Array
(
[------------------------------d2bcc8532b06
Content-Disposition:_form-data;_name] => "1"
Array
------------------------------d2bcc8532b06
Content-Disposition: form-data; name="2"
Array
------------------------------d2bcc8532b06--
)
There is not much difference as I can see. Why?
Question 2) In the above output, I can see just the values i.e. 1 and 2 and not the key i.e. ‘a’ and ‘b’…why are they not included in the output?
Thanks