Create Your Own Custom API - The Client
(Page 3 of 6 )
Now we need to set up the client. Here, I've developed a cURL request (I used this because cURL is "big" and readily available and fairly simple to use). For testing purposes we are only going to have our static request XML message sent.
<?php $request = "<?xml version="1.0"?> <myXML> <function>order</function> <values> <orderID>12345</orderID> <reference>ref</reference> </values> </myXML> ";
$url = "http://www.mydomain.com/my_server.php"; // fake - obviosly!
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $request); // what to post curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $result = curl_exec($ch); curl_close($ch);
print $result; ?> |
You will want to set the $url variable to the location of your server (that we are about to set up!). Other than that - the setup of the client application is simple!
Also note the "curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);" line. Include this so the XML returned is returned as a string (so we can set the variable, parse the information, and use what was returned). Next - on to the server...
Next: The Server >>
More Miscellaneous Articles
More By Codewalkers