Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.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使用HTTP POST发送XML数据_Php_Xml_Http_Codeigniter_Post - Fatal编程技术网

通过PHP使用HTTP POST发送XML数据

通过PHP使用HTTP POST发送XML数据,php,xml,http,codeigniter,post,Php,Xml,Http,Codeigniter,Post,我需要发送这个XML <?xml version="1.0" encoding="UTF-8"?> <gate> <country>NO</country> <accessNumber>1900</accessNumber> <senderNumber>1900</senderNumber> <targetNumber>4792267523</ta

我需要发送这个XML

      <?xml version="1.0" encoding="UTF-8"?>
<gate>
   <country>NO</country>
   <accessNumber>1900</accessNumber>
   <senderNumber>1900</senderNumber>
   <targetNumber>4792267523</targetNumber>
   <price>0</price>
   <sms>
      <content><![CDATA[This is a test æøå ÆØÅ]]></content>
   </sms>
</gate>

不
1900
1900
4792267523
0
到SMS网关服务。该服务侦听HTTP POST请求。XML必须嵌入POST请求的主体中


我使用的是PHP和CodeIgniter框架,但我完全是一个PHP n00b,因此理想情况下我需要一个全面的指南,但任何指向正确方向的指针都会受到欢迎。

您可以使用cURL库发布数据:


如果postfield包含需要发送的XML,则需要为API服务(我猜是Clickatell)期望的postfield命名

另一个选项是
file\u get\u contents()


是的,我希望。。。我问IT人员是否可以安装cURL,但他不可能在合理的时间内完成。然后,请看这篇博文:还有功能强大且非常好的pecl_http扩展和各种PEAR http_*包(让IT人员更容易安装)。@dusoft-感谢您链接到netevil.orgyeah,PHP4.3中引入了流,但对大多数用户来说是隐藏的。我得到了错误:{警告:file_get_contents()[function.file get contents]:打开流失败:HTTP请求失败!在第42行的/home/phretscl/public_html/xml/pulldata.PHP中找不到HTTP/1.404}等等,问题不是“如何发送xml”而不是“如何接收XML并读取它”?
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_URL, "http://websiteURL");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "XML=".$xmlcontent."&password=".$password."&etc=etc");
$content=curl_exec($ch);
// $xml_str = your xml
// $url = target url

$post_data = array('xml' => $xml_str);
$stream_options = array(
    'http' => array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded' . "\r\n",
        'content' =>  http_build_query($post_data)));

$context  = stream_context_create($stream_options);
$response = file_get_contents($url, null, $context);