尝试将以下XML数据发送到下面的URL。
$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>";
响应应该是“ OK”,但它只是空白。
debug.log有以下错误。
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
我注意到URL将“&”更改为“&”。如果我将网址直接放入浏览器,则不会起作用,但是如果我删除了“ amp;”,它给了我好的答复。
但是,如果我从代码“ false,$ context”中删除例如file_get_contents($createjob_url)
,响应返回“ OK”,那么该URL就可以了。
我正在使用Google App Engine,因此无法使用cURL。
我认为这与我的流选项有关吗?任何反馈将不胜感激。
看来我的问题是几件小事。
对于我要解析的特定URL,我不需要XML标记,因此将其删除 <?xml version='1.0' encoding='utf-8'?>
他们还希望内容类型为xml,因此将其更改为 'header' => "Content-type: text/xml"
一旦我把这两个排序,一切都很好:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句