HTTP Request Listener
| From: | Ian Warner | Date: | Wed, 26 Jul 2006 17:26:16 +0000 |
| Subject: | HTTP Request Listener | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-24779@lists.php.net to get a copy of this message | ||
Hi
Having problems trying to find out how to install the listener, here is my function:
Says I need to attach the listener in the code ?
Any help or example appreciated:
I will then document on my wiki - http://wiki.triangle-solutions.com/index.php/PEAR_HTTP_Request
function sendCall($url, $params)
{
if (!isset($params['method']) && ($params['method'] != 'GET'
|| $params['method'] != 'POST' || $params['method'] != 'PUT')) {
return PEAR::raiseError('Incorrect sendCall Paramater - ' .
$params['method']);
}
// If HTTP_Request is not available then quit and raise error.
if (!include_once 'HTTP/Request.php') {
return PEAR::raiseError('Missing PEAR package HTTP_Request.');
}
require_once 'HTTP/Request/Listener.php';
$req = new HTTP_Request($this->_base_url, $params);
$req->addHeader('Content-Type', 'text/xml');
// If method is POST then use the addPostData otherwise it should be
// addQueryString for GET command.
if ($params['method'] == 'POST') {
foreach ($url as $k => $v) {
$req->addPostData($k, $v);
}
} elseif ($params['method'] == 'GET') {
foreach ($url as $k => $v) {
$req->addQueryString($k, $v);
}
} elseif ($params['method'] == 'PUT') {
foreach ($url as $k) {
$req->addRawPostData($k, false);
}
}
$req->attach();
$req->sendRequest(false);
if ($req->getResponseCode() != 200) {
return PEAR::raiseError('Could not open - ' . $this->_base_url);
}
echo $req->getResponseBody();
return $req->getResponseBody();
}