1

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.

1 Answer 1

2

So looks like my issue was a couple of small things.

For the particular URL I was parsing to, I didnt need to have the XML tag, so removed <?xml version='1.0' encoding='utf-8'?>

They also wanted the content type as xml, so changed it to 'header' => "Content-type: text/xml"

Once I got these two sorted, all worked well :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.