note 50726 deleted from ref.xml by bjori
| From: | bjori@php.net | Date: | Mon, 09 Oct 2006 11:15:41 +0000 |
| Subject: | note 50726 deleted from ref.xml by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-118296@lists.php.net to get a copy of this message | ||
Note Submitter: john at etechdata dot com dot au
----
This code uses CURL to connect to a server and post XML info to it and then capture the response
from the server. I spent hours trying to find the solution and it's really quite simple. Easy
to say AFTER you find the answer. Hope it helps someone.
<?php
// store your XML code into a variable line by line
// this is simply an example. you should replace it with your XML code
$XPost = "<?xml version='1.0' encoding='UTF-8'?>";
$XPost .= "<XMLCodeBody>";
$XPost .= "<MessageInfo>";
$XPost .= "<messageID>8af793f9af34bea0ecd7eff71c94d6</messageID>";
$XPost .= "<messageTimestamp>20040710050758444000+600</messageTimestamp>";
$XPost .= "<timeoutValue>60</timeoutValue>";
$XPost .= "<apiVersion>spxml-3.0</apiVersion>";
$XPost .= "</MessageInfo>";
$XPost .= "</XMLCodeBody>";
$url = "https://www.urltopost.data.to";
// enter the URL to post to here
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_HEADER, 1); // capture the returned headers
curl_setopt($ch, CURLOPT_TIMEOUT, 4); // times out after 4s
curl_setopt($ch, CURLOPT_POSTFIELDS, $XPost); // add POST fields
$result = curl_exec($ch); // run the whole process
// the headers returned from the server will now be stored in $result
// for now display the result to screen
echo "<pre>";
print_r($result);
echo "</pre>";
// once you have the result you can simply extract the response and use it.
?>