本文整理汇总了PHP中HTTP_Request::getRequestCode方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP_Request::getRequestCode方法的具体用法?PHP HTTP_Request::getRequestCode怎么用?PHP HTTP_Request::getRequestCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTP_Request
的用法示例。
在下文中一共展示了HTTP_Request::getRequestCode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: send
/**
* send
* This method sends a trackback to the trackback_url saved in it. The
* data array of the trackback object can be completed by submitting the
* necessary data through the $data parameter of this method.
* The following data has to be set to call this method:
* 'title' Title of the weblog entry sending the trackback.
* 'url' URL of the weblog entry sending the trackback.
* 'excerpt' Excerpt of the weblog entry sending the trackback.
* 'blog_name' Name of the weblog sending the trackback.
* 'trackback_url' URL to send the trackback to.
* Services_Trackback::send() requires PEAR::HTTP_Request. The options for the HTTP_Request
* object are stored in the global options array using the key 'http_request'.
*
* @since 0.3.0
* @access public
* @param string $data Additional data to complete the trackback.
* @return mixed True on success, otherwise PEAR_Error.
*/
function send($data = null)
{
// Load HTTP_Request
@(require_once 'HTTP/Request.php');
if (!class_exists('HTTP_Request')) {
return PEAR::raiseError('Unable to load PEAR::HTTP_Request.');
}
// Consistancy check
if (!isset($data)) {
$data = array();
}
$this->_data = array_merge($this->_data, $data);
$necessaryData = array('title', 'url', 'excerpt', 'blog_name', 'trackback_url');
$res = $this->_checkData($necessaryData);
if (PEAR::isError($res)) {
return $res;
}
// Get URL
$url = str_replace('&', '&', $this->_data['trackback_url']);
// Changed in 0.5.0 All HTTP_Request options are now supported.
$options = $this->_options['httpRequest'];
$options['timeout'] = $this->_options['timeout'];
// Create new HTTP_Request
$req = new HTTP_Request($url, $options);
$req->setMethod(HTTP_REQUEST_METHOD_POST);
// Add HTTP headers
$req->addHeader("User-Agent", $options['useragent']);
// Adding data to send
$req->addPostData('url', $this->_data['url']);
$req->addPostData('title', $this->_data['title']);
$req->addPostData('blog_name', $this->_data['blog_name']);
$req->addPostData('excerpt', strip_tags($this->_data['excerpt']));
// Send POST request
$res = $req->sendRequest();
if (PEAR::isError($res)) {
return $res;
}
// Check return code
if ($req->getResponseCode() != 200) {
return PEAR::raiseError('Host returned Error ' . $req->getRequestCode() . '.');
}
return $this->_interpretTrackbackResponse($req->getResponseBody());
}