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

问题描述:

我需要发送此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>

到SMS网关服务。该服务侦听HTTP POST请求。 XML必须嵌入在POST请求的BODY中。

to a SMS gateway service. The service listens for HTTP POST requests. The XML must be embedded in the BODY of the POST request.

我使用的是PHP和CodeIgniter框架,但我是一个总的PHP n00b,所以理想情况下我

I'm using PHP and the CodeIgniter framework, but I'm a total PHP n00b, so ideally I'd need a thorough guide, but any pointers in the right direction would be appreciated.

您可以使用cURL库进行发布数据:
http://www.php.net/curl

you can use cURL library for posting data: http://www.php.net/curl

$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);

其中postfield包含您需要发送的XML - 您需要为API服务命名postfield我猜)

where postfield contains XML you need to send - you will need to name the postfield the API service (Clickatell I guess) expects