Sending SMS Thru HTTP - Sending the request with CURL
(Page 4 of 36 )
Previously we saw that the request could be executed by pasting it into the browser window. But what we really want is for this to take place behind the scenes. The following code does exactly that using CURL.
CURL is a very impressive library that allows you to connect and communicate to many different types of servers with many different types of protocols. You can find more info in the PHP Manual.
This code opens up a connection with the gateway, sends the SMS message(s) and collects their message IDs which are presented within the response header.
<?php $url = "http://www.tm4b.com/client/api/send.php"; //this is the url of the gateway's interface $ch = curl_init; //initialize curl handle curl_setopt($ch, CURLOPT_URL, $url); //set the url curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); //return as a variable curl_setopt($ch, CURLOPT_POST, 1); //set POST method curl_setopt($ch, CURLOPT_POSTFIELDS, $request); //set the POST variables $response = curl_exec($ch); //run the whole process and return the response curl_close($ch); //close the curl handle //print $response; //show the result onscreen for debugging ?> |
First, we initialize a new CURL session. Then we set our desired options; this includes setting CURLOPT_POST because TM4B's SMS API requires us to send multiple messages using POST. Finally we execute the call and then close the handle.
Next: Sending the Request with Sockets >>
More Miscellaneous Articles
More By Codewalkers
|
| · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | | |
|