Hi!
I need to make a request to an API, using REST (POST method) in PHP.
But the data needs to be in XML format. How can I send REST requests with XML data?
Thank you!
Hi!
I need to make a request to an API, using REST (POST method) in PHP.
But the data needs to be in XML format. How can I send REST requests with XML data?
Thank you!
This can be used to finely set several headers - POST
, PUT
, DELETE
- for you REST request as well as send a payload - your XML content.
I used "fopen" and it works.
//You can use 'POST','GET','PUT' or 'DELETE'
$opts = array(
'http'=>array(
'method'=>'POST',
'header'=>"Content-Type: text/xml\r\n" .
$auth."\r\n",
'content'=>$xml
)
);
$context = stream_context_create($opts);
/* Sends an http request to www.example.com
with additional headers shown above */
$fp = fopen($url, 'r', false, $context);
fpassthru($fp);
fclose($fp);