I need to send this 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>
to a SMS gateway service. The service listens for HTTP POST requests. The XML must be embedded in the BODY of the POST request.
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.
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);
where postfield contains XML you need to send - you will need to name the postfield the API service (Clickatell I guess) expects
Another option would be file_get_contents()
:
// $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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With