I have an XML
file i want to send via POST to an URL.
This is my code for it:
$url = "http://someurl.com";
$xml = file_get_contents('xml_api_actionsInsert_sample.xml');
$post_data = array('xml' => $xml);
$stream_options = array(
'http' => array(
'method' => 'POST',
'header' => 'ContentType: text/xml; charset=UTF8',
'content' => http_build_query($post_data)));
$context = stream_context_create($stream_options);
$response = file_get_contents($url, null, $context);
The requirement is that the header Content-Type
must be
ContentType: text/xml; charset=UTF8
and that the Request only contains valid XML. The xml file is valid but i'm getting an error from the API
error: Request contains no XML
Is there a mistake how i send/load the XML? Or should i try another way of sending the Request like cURL
?