使用HTTP POST使用PHP发送XML数据 [英] Sending XML data using HTTP POST with PHP

查看:143
本文介绍了使用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

这篇关于使用HTTP POST使用PHP发送XML数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆