本文整理汇总了PHP中HTTP_Request::getResponseCode方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP_Request::getResponseCode方法的具体用法?PHP HTTP_Request::getResponseCode怎么用?PHP HTTP_Request::getResponseCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTP_Request
的用法示例。
在下文中一共展示了HTTP_Request::getResponseCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: makeAPICall
/**
* @param $uri
*
* @return SimpleXMLElement
* @throws Exception
*/
public static function makeAPICall($uri)
{
require_once 'HTTP/Request.php';
$params = array('method' => HTTP_REQUEST_METHOD_GET, 'allowRedirects' => FALSE);
$request = new HTTP_Request(self::$_apiURL . $uri, $params);
$result = $request->sendRequest();
if (PEAR::isError($result)) {
CRM_Core_Error::fatal($result->getMessage());
}
if ($request->getResponseCode() != 200) {
CRM_Core_Error::fatal(ts('Invalid response code received from Sunlight servers: %1', array(1 => $request->getResponseCode())));
}
$string = $request->getResponseBody();
return simplexml_load_string($string);
}
示例2: retrieveFile
/**
* Retrieves data from cache, if it's there. If it is, but it's expired,
* it performs a conditional GET to see if the data is updated. If it
* isn't, it down updates the modification time of the cache file and
* returns the data. If the cache is not there, or the remote file has been
* modified, it is downloaded and cached.
*
* @param string URL of remote file to retrieve
* @param int Length of time to cache file locally before asking the server
* if it changed.
* @return string File contents
*/
function retrieveFile($url, $cacheLength, $cacheDir)
{
$cacheID = md5($url);
$cache = new Cache_Lite(array("cacheDir" => $cacheDir, "lifeTime" => $cacheLength));
if ($data = $cache->get($cacheID)) {
return $data;
} else {
// we need to perform a request, so include HTTP_Request
include_once 'HTTP/Request.php';
// HTTP_Request has moronic redirect "handling", turn that off (Alexey Borzov)
$req = new HTTP_Request($url, array('allowRedirects' => false));
// if $cache->get($cacheID) found the file, but it was expired,
// $cache->_file will exist
if (isset($cache->_file) && file_exists($cache->_file)) {
$req->addHeader('If-Modified-Since', gmdate("D, d M Y H:i:s", filemtime($cache->_file)) . " GMT");
}
$req->sendRequest();
if (!($req->getResponseCode() == 304)) {
// data is changed, so save it to cache
$data = $req->getResponseBody();
$cache->save($data, $cacheID);
return $data;
} else {
// retrieve the data, since the first time we did this failed
if ($data = $cache->get($cacheID, 'default', true)) {
return $data;
}
}
}
Services_ExchangeRates::raiseError("Unable to retrieve file {$url} (unknown reason)", SERVICES_EXCHANGERATES_ERROR_RETRIEVAL_FAILED);
return false;
}
示例3: setInputFile
/**
* Sets the input xml file to be parsed
*
* @access public
* @param string $file Filename(full path)
* @return mixed True on success or error on failure
*/
function setInputFile($file)
{
require_once PEAR_PATH . 'HTTP/Request.php';
$httpRequest = new HTTP_Request($file, $this->_params);
$httpRequest->setMethod(HTTP_REQUEST_METHOD_GET);
$resRequest = $httpRequest->sendRequest();
if (PEAR::isError($resRequest)) {
return $resRequest;
} elseif ($httpRequest->getResponseCode() != 200) {
return $this->raiseError('HTTP response error', HTTP_REQUEST_ERROR_RESPONSE);
}
$data = trim($httpRequest->getResponseBody());
if (version_compare(PHP_VERSION, '5.0.0', '<')) {
if (preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/m', $data, $matches)) {
$srcenc = strtoupper($matches[1]);
if (!in_array($srcenc, $this->_validEncodings)) {
if (function_exists('iconv')) {
$data = @iconv($srcenc, 'UTF-8', $data);
} elseif (function_exists('mb_list_encodings') && in_array($srcenc, array_map('strtoupper', mb_list_encodings()))) {
$data = @mb_convert_encoding($data, 'UTF-8', $srcenc);
}
}
}
}
$this->setInputString($data);
return true;
}
示例4: prepare
/**
* preprocess Index action.
*
* @access public
* @return string Forward name (null if no errors.)
*/
function prepare()
{
if ($this->af->validate() == 0) {
/// download file
$url = sprintf('%s/repository.sphp', rtrim($this->af->get('repository_url'), '/'));
$cache_file = $this->backend->ctl->repositoryURL2CacheFile($url);
$repo_data = unserialize(file_get_contents($cache_file));
list($package, $version) = explode('@', $this->af->get('target_package'));
$urls = array();
foreach ($repo_data as $package_name => $package_data) {
if ($package_name == $package) {
foreach ($package_data as $_pdata) {
if ($_pdata['version'] == $version) {
$urls = $_pdata['urls'];
$filesize = $_pdata['size'];
}
}
}
}
require_once 'HTTP/Request.php';
$req = new HTTP_Request();
$req->setMethod(HTTP_REQUEST_METHOD_HEAD);
$command = 'no command';
foreach ($urls as $_url_data) {
$_url = $_url_data['url'];
$req->setURL($_url);
$req->sendRequest();
if ($req->getResponseCode() == "302") {
$headers = $req->getResponseHeader();
$req->setURL($headers['location']);
}
$req->sendRequest();
if ($req->getResponseCode() == '200') {
$data_file = $this->backend->ctl->package2dataFile($package, $version);
if ($this->fetchTgzFile($data_file, $req->getUrl())) {
if (filesize($data_file) == $filesize || !$filesize) {
chmod($data_file, 0666);
return null;
}
}
}
}
$this->ae->add('wget failed', _('file download failed.') . '[debug]' . sprintf('SIZE:[datafile,%d => repos,%d]', filesize($data_file), $filesize));
}
return 'json_error_reload';
}
示例5:
/**
* serendipity_plugin_zooomr::getURL()
* downloads the content from an URL and returns it as a string
*
* @author Stefan Lange-Hegermann
* @since 02.08.2006
* @param string $url URL to get
* @return string downloaded Data from "$url"
*/
function get_url($url)
{
require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
$req = new HTTP_Request($url);
if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') {
$store = file_get_contents($url);
} else {
$store = $req->getResponseBody();
}
return $store;
}
示例6: sendRequest
function sendRequest($return_body = true)
{
$this->Response = $this->HttpRequest->sendRequest();
$this->code = $this->HttpRequest->getResponseCode();
if (PEAR::isError($this->Response)) {
$this->error = $this->Response->getMessage();
return false;
} else {
return $return_body ? $this->HttpRequest->getResponseBody() : true;
}
}
示例7: getURL
/**
*
*/
function getURL($url)
{
require_once PEAR_PATH . 'HTTP/Request.php';
$httpRequest = new HTTP_Request($url);
$httpRequest->setMethod(HTTP_REQUEST_METHOD_GET);
$resRequest = $httpRequest->sendRequest();
if (!PEAR::isError($resRequest) && $httpRequest->getResponseCode() == 200) {
$data = $httpRequest->getResponseBody();
} else {
$data = @file_get_contents($url);
}
return $data;
}
示例8: PNB_getPingbackUrl
/**
* Get the Pingback URL for a given URL
*
* @param string $url URL to get the Pingback URL for
* @return string Pingback URL or empty string
*
*/
function PNB_getPingbackUrl($url)
{
require_once 'HTTP/Request.php';
$retval = '';
$req = new HTTP_Request($url);
$req->setMethod(HTTP_REQUEST_METHOD_HEAD);
$req->addHeader('User-Agent', 'glFusion/' . GVERSION);
$response = $req->sendRequest();
if (PEAR::isError($response)) {
COM_errorLog('Pingback (HEAD): ' . $response->getMessage());
return false;
} else {
$retval = $req->getResponseHeader('X-Pingback');
}
if (empty($retval)) {
// search for <link rel="pingback">
$req = new HTTP_Request($url);
$req->setMethod(HTTP_REQUEST_METHOD_GET);
$req->addHeader('User-Agent', 'glFusion/' . GVERSION);
$response = $req->sendRequest();
if (PEAR::isError($response)) {
COM_errorLog('Pingback (GET): ' . $response->getMessage());
return false;
} elseif ($req->getResponseCode() == 200) {
$body = $req->getResponseBody();
// only search for the first match - it doesn't make sense to have
// more than one pingback URL
$found = preg_match("/<link rel=\"pingback\"[^>]*href=[\"']([^\"']*)[\"'][^>]*>/i", $body, $matches);
if ($found === 1 && !empty($matches[1])) {
$url = str_replace('&', '&', $matches[1]);
$retval = urldecode($url);
}
} else {
COM_errorLog('Pingback (GET): Got HTTP response code ' . $req->getResponseCode() . " when requesting {$url}");
return false;
}
}
return $retval;
}
示例9: checkAddress
/**
* @param $values
*
* @return bool
*/
public static function checkAddress(&$values)
{
if (self::$_disabled) {
return FALSE;
}
if (!isset($values['street_address']) || !isset($values['city']) && !isset($values['state_province']) && !isset($values['postal_code'])) {
return FALSE;
}
$userID = Civi::settings()->get('address_standardization_userid');
$url = Civi::settings()->get('address_standardization_url');
if (empty($userID) || empty($url)) {
return FALSE;
}
$address2 = str_replace(',', '', $values['street_address']);
$XMLQuery = '<AddressValidateRequest USERID="' . $userID . '"><Address ID="0"><Address1>' . CRM_Utils_Array::value('supplemental_address_1', $values, '') . '</Address1><Address2>' . $address2 . '</Address2><City>' . $values['city'] . '</City><State>' . $values['state_province'] . '</State><Zip5>' . $values['postal_code'] . '</Zip5><Zip4>' . CRM_Utils_Array::value('postal_code_suffix', $values, '') . '</Zip4></Address></AddressValidateRequest>';
require_once 'HTTP/Request.php';
$request = new HTTP_Request();
$request->setURL($url);
$request->addQueryString('API', 'Verify');
$request->addQueryString('XML', $XMLQuery);
$response = $request->sendRequest();
$session = CRM_Core_Session::singleton();
$code = $request->getResponseCode();
if ($code != 200) {
$session->setStatus(ts('USPS Address Lookup Failed with HTTP status code: %1', array(1 => $code)));
return FALSE;
}
$responseBody = $request->getResponseBody();
$xml = simplexml_load_string($responseBody);
if (is_null($xml) || is_null($xml->Address)) {
$session->setStatus(ts('Your USPS API Lookup has Failed.'));
return FALSE;
}
if ($xml->Number == '80040b1a') {
$session->setStatus(ts('Your USPS API Authorization has Failed.'));
return FALSE;
}
if (array_key_exists('Error', $xml->Address)) {
$session->setStatus(ts('Address not found in USPS database.'));
return FALSE;
}
$values['street_address'] = (string) $xml->Address->Address2;
$values['city'] = (string) $xml->Address->City;
$values['state_province'] = (string) $xml->Address->State;
$values['postal_code'] = (string) $xml->Address->Zip5;
$values['postal_code_suffix'] = (string) $xml->Address->Zip4;
if (array_key_exists('Address1', $xml->Address)) {
$values['supplemental_address_1'] = (string) $xml->Address->Address1;
}
return TRUE;
}
示例10: doHeadRequest
/**
* Send an HTTP HEAD request for the given URL
*
* @param string $url URL to request
* @param string &$errmsg error message, if any (on return)
* @return int HTTP response code or 777 on error
*
*/
function doHeadRequest($url, &$errmsg)
{
require_once 'HTTP/Request.php';
$req = new HTTP_Request($url);
$req->setMethod(HTTP_REQUEST_METHOD_HEAD);
$req->addHeader('User-Agent', 'Geeklog/' . VERSION);
$response = $req->sendRequest();
if (PEAR::isError($response)) {
$errmsg = $response->getMessage();
return 777;
} else {
return $req->getResponseCode();
}
}
示例11: call
/**
* @throws BadRequestException
* @param $method
* @param $args
* @return mixed
*/
public function call($method, $args)
{
$req = new HTTP_Request($this->conf->endpoint . $method);
$req->setMethod('POST');
$args['app_id'] = $this->conf->app_id;
foreach ($args as $key => $value) {
$req->addPostData($key, $value);
}
$sig = sign($args, $this->conf->key);
$req->addPostData('signature', $sig['signature']);
$req->addPostData('time', $sig['time']);
$req->sendRequest();
if ($req->getResponseCode() != 200) {
throw new BadRequestException($req->getResponseBody());
}
return json_decode($req->getResponseBody());
}
示例12: _update
/**
* Submit REST Request to write data
*
* @param string $xml The command to execute
* @return mixed Boolean true on success or PEAR_Error
* @access private
*/
private function _update($xml)
{
global $configArray;
global $timer;
$this->client->setMethod('POST');
$this->client->setURL($this->host . "/update/");
if ($this->debug) {
echo "<pre>POST: ";
print_r($this->host . "/update/");
echo "XML:\n";
print_r($xml);
echo "</pre>\n";
}
// Set up XML
$this->client->addHeader('Content-Type', 'text/xml; charset=utf-8');
$this->client->addHeader('Content-Length', strlen($xml));
$this->client->setBody($xml);
// Send Request
$result = $this->client->sendRequest();
$responseCode = $this->client->getResponseCode();
//$this->client->clearPostData();
if ($responseCode == 500 || $responseCode == 400) {
$detail = $this->client->getResponseBody();
$timer->logTime("Send the update request");
// Attempt to extract the most useful error message from the response:
if (preg_match("/<title>(.*)<\\/title>/msi", $detail, $matches)) {
$errorMsg = $matches[1];
} else {
$errorMsg = $detail;
}
global $logger;
$logger->log("Error updating document\r\n{$xml}", PEAR_LOG_DEBUG);
return new PEAR_Error("Unexpected response -- " . $errorMsg);
} elseif ($configArray['System']['debugSolr'] == true) {
$this->client->getResponseBody();
$timer->logTime("Get response body");
// Attempt to extract the most useful error message from the response:
//print_r("Update Response:");
//print_r($detail);
}
if (!PEAR_Singleton::isError($result)) {
return true;
} else {
return $result;
}
}
示例13: getXMLArray
function getXMLArray($file, $forced_encoding = null)
{
require_once (defined('S9Y_PEAR_PATH') ? S9Y_PEAR_PATH : S9Y_INCLUDE_PATH . 'bundled-libs/') . 'HTTP/Request.php';
$req = new HTTP_Request($file);
if (PEAR::isError($req->sendRequest()) || $req->getResponseCode() != '200') {
if (ini_get("allow_url_fopen")) {
$data = file_get_contents($file);
} else {
$data = "";
}
} else {
$data = $req->getResponseBody();
}
if (trim($data) == '') {
return false;
}
return $this->parseXML($data, $forced_encoding);
}
示例14: prepare
/**
* preprocess Index action.
*
* @access public
* @return string Forward name (null if no errors.)
*/
function prepare()
{
if ($this->af->validate() == 0) {
$url = sprintf('%s/repository.sphp', rtrim($this->af->get('repository_url'), '/'));
require_once 'HTTP/Request.php';
$req = new HTTP_Request($url);
$req->sendRequest();
if ($req->getResponseCode() == '200') {
$data = $req->getResponseBody();
$ret = @unserialize($data);
if (is_array($ret)) {
$this->af->setApp('repository_data', $ret);
$cache_file = $this->backend->ctl->repositoryURL2CacheFile($url);
file_put_contents($cache_file, $data);
chmod($cache_file, 0666);
return null;
}
}
}
$this->ae->add('repository_url', _('The repository is not available!'));
return 'json_error';
}
示例15: willRequest
function willRequest($request)
{
// お気に入り作成をフックする
if (preg_match("|^/favorites/create/(\\d+)|", $this->server->request['path'], $match)) {
$id = $match[1];
$url = $this->server->config['Twitter']['api'];
$url .= '/status/show/' . $id . '.json';
$req = new HTTP_Request($url);
if (isset($_SERVER["PHP_AUTH_USER"])) {
$req->setBasicAuth($_SERVER["PHP_AUTH_USER"], @$_SERVER["PHP_AUTH_PW"]);
}
$result = $req->sendRequest();
if (PEAR::isError($result)) {
return;
}
if ($req->getResponseCode() != 200) {
return;
}
$json = json_decode($req->getResponseBody());
$title = $json->text;
$href = 'http://twitter.com/' . $json->user->screen_name . '/status/' . $id;
$created = date('Y-m-d\\TH:i:s\\Z');
$nonce = pack('H*', sha1(md5(time())));
$pass_digest = base64_encode(pack('H*', sha1($nonce . $created . $this->server->config['Plugin']['HatenaBookmark']['password'])));
$wsse = 'UsernameToken Username="' . $this->server->config['Plugin']['HatenaBookmark']['id'] . '", ';
$wsse .= 'PasswordDigest="' . $pass_digest . '", ';
$wsse .= 'Nonce="' . base64_encode($nonce) . '",';
$wsse .= 'Created="' . $created . '"';
$req = new HTTP_Request('http://b.hatena.ne.jp/atom/post');
$req->setMethod(HTTP_REQUEST_METHOD_POST);
$req->addHeader('WWW-Authenticate', 'WSSE profile="UsernameToken"');
$req->addHeader('X-WSSE', $wsse);
$req->addHeader('Content-Type', 'application/x.atom+xml');
$xml = '<?xml version="1.0" encoding="utf-8"?>' . '<entry xmlns="http://purl.org/atom/ns#">' . '<title>' . $title . '</title>' . '<link rel="related" type="text/html" href="' . $href . '" />' . '<summary type="text/plain"></summary>' . '</entry>';
$req->addRawPostData($xml);
$req->sendRequest();
}
return $request;
}