Sending XML to URL in PHP (without cURL) -
trying send following xml data 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', blank.
the debug.log has following error.
php warning:  file_get_contents(https:<url>?apikey=[apikey]&accountkey=[accountkey]): failed open stream: http request failed! http/1.1 500 internal server error   i noticed url changes '&' '&'. if put url directly browser, doesnt work, if remove 'amp;' gives me ok response.
but if remove code 'false, $context' e.g. file_get_contents($createjob_url), response comes 'ok', url fine. 
i using google app engine hence unable use curl.
i assume has stream options? feedback appreciated.
so looks issue couple of small things.
for particular url parsing to, didnt need have xml tag, removed <?xml version='1.0' encoding='utf-8'?>
they wanted content type xml, changed 'header' => "content-type: text/xml"
once got these 2 sorted, worked :)
Comments
Post a Comment