Trying to send the following XML data to URL below.
$xml="<?xml version='1.0' encoding='utf-8'?>
<Job>
<Name>Set-up - ".$client_name."</Name>
<Description></Description>
<ClientID>".$accountantid."</ClientID>
<StartDate>".$start_date."</StartDate>
<DueDate>".$due_date."</DueDate>
<TemplateID>".$templateid."</TemplateIDr>
</Job>";
$createjob_url="https:<url>apiKey=[apikey]&accountKey=[accountkey]";
$stream_options = array (
'http' => array (
'method' => "POST",
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'content' => $xml
)
);
$context=stream_context_create($stream_options);
$response=file_get_contents($createjob_url, false, $context);
echo "<p>".$response."</p>";
The response should come out 'OK', but its just blank.
The debug.log has the following error.
PHP Warning: file_get_contents(https:<url>?apiKey=[apikey]&accountKey=[accountkey]): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error
I noticed the URL changes the '&' to '&'. If I put the url directly into the browser, it doesnt work, however if I remove 'amp;' it gives me the OK response.
But then if I remove from the code 'false, $context' e.g. file_get_contents($createjob_url), the response comes back 'OK', so the URL is fine.
I am using Google App Engine hence unable to use cURL.
I assume it has something to do with my stream options? Any feedback would be greatly appreciated.