note 50726 added to ref.xml
| From: | john at etechdata dot com dot au | Date: | Tue, 08 Mar 2005 10:42:26 +0000 |
| Subject: | note 50726 added to ref.xml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-86094@lists.php.net to get a copy of this message | ||
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.
?>
----
Manual Page -- http://www.php.net/manual/en/ref.xml.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50726
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50726&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50726&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50726&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50726&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50726&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50726&report=yes
Search -- http://master.php.net/manage/user-notes.php