note 55433 added to ref.xml
| From: | japplega at hain-celestial dot com | Date: | Wed, 03 Aug 2005 14:09:12 +0000 |
| Subject: | note 55433 added to ref.xml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-93006@lists.php.net to get a copy of this message | ||
Here is some code showing how to post XML to a server via HTTP using the PEAR HTTP_Request class. I
struggled with this for a while, looking for an alternative to using CURL, so here it is. The trick
is to use the addRawPostData() method which is not well documented.
<?php
// store your XML into a variable. This is just an example; you would
// use your own XML (XML borrowed from john at etechdata's post)
$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>";
require_once "HTTP/Request.php";
$url = "http://www.urltopost.data.to";
$req =& new HTTP_Request($url);
$req->setMethod(HTTP_REQUEST_METHOD_POST);
$req->addHeader("Content-Type", "application/xml");
$req->addRawPostData($XPost);
$response = $req->sendRequest();
if (PEAR::isError($response)) {
// deal with error
} else {
$result = $req->getResponseBody();
}
?>
----
Manual Page -- http://www.php.net/manual/en/ref.xml.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55433
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55433&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55433&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55433&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55433&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55433&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55433&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55433&report=yes
Search -- http://master.php.net/manage/user-notes.php