Re: Web Services
| From: | Erik Price | Date: | Wed, 26 Jun 2002 15:08:28 +0000 |
| Subject: | Re: Web Services | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-103977@lists.php.net to get a copy of this message | ||
On Wednesday, June 26, 2002, at 10:49 AM, Laurent Drouet wrote:
I would like to know if there is a way to request data from a web services for example http://glkev.net.innerhost.com/glkev_ws/Currencyws.asmx using php without java ?If you know the web services API, you just send your request. It shouldn't matter whether you're using Java, PHP, Python, even VB or even Telnet to generate your request -- most web services accept an HTTP POST message consisting of XML code which is used to perform some kind of action. There are two things you can do -- either use the cURL functions (your PHP binary must be compiled with cURL enabled to do this), which give you an advanced set of URL accesses, or open a socket to the remote machine with the web service and send a stream of POST data that way. You can use Rasmus Lerdorf's "postToHost" function (this may as well just become a PHP function, it gets referenced so much), which I have appended to this message. Either way, just generate your XML string and fire it at the remote machine. You will need to write code to handle the response, obviously. # =============================================================== # PostToHost($host, $path, $data_to_send) # --------------------------------------------------------------- # "It is a trivial little function." # -Rasmus # =============================================================== function PostToHost($host, $path, $data_to_send) { $fp = fsockopen($host,80); fputs($fp, "POST $path HTTP/1.0\n"); fputs($fp, "Host: $host\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\n"); fputs($fp, "Content-length: " . strlen($data_to_send) . "\n"); fputs($fp, "Connection: close\n\n"); fputs($fp, $data_to_send); while(!feof($fp)) { echo fgets($fp, 128); } fclose($fp); } Erik ---- Erik Price Web Developer Temp Media Lab, H.H. Brown pricee@hhbrown.com