note 55433 deleted from ref.xml by sean
| From: | sean@php.net | Date: | Wed, 03 Aug 2005 14:15:15 +0000 |
| Subject: | note 55433 deleted from ref.xml by sean | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-93011@lists.php.net to get a copy of this message | ||
Note Submitter: japplega at hain-celestial dot com
----
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();
}
?>