Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中将POST XML发送到URL_Php_Xml - Fatal编程技术网

在PHP中将POST XML发送到URL

在PHP中将POST XML发送到URL,php,xml,Php,Xml,我有一个XML文件要通过POST发送到URL 这是我的代码: $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',

我有一个XML文件要通过POST发送到URL

这是我的代码:

$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'  => 'Content­Type: text/xml; charset=UTF­8',
        'content' =>  http_build_query($post_data)));

$context  = stream_context_create($stream_options);
$response = file_get_contents($url, null, $context);
要求是标题内容类型必须为

并且请求只包含有效的XML。xml文件是有效的,但API中有一个错误

error: Request contains no XML

我如何发送/加载XML是否有错误?或者我应该尝试另一种发送请求的方式,比如cURL?

您确定应该发送一个键值对xml=>?也许它希望你只发送XML字符串作为内容。@SergiuParaschiv,伙计,我是盲人,谢谢你,你能添加这个作为答案,这样我就可以接受它吗?
error: Request contains no XML