本文整理汇总了PHP中HTTP_Request2::getURL方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP_Request2::getURL方法的具体用法?PHP HTTP_Request2::getURL怎么用?PHP HTTP_Request2::getURL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTP_Request2
的用法示例。
在下文中一共展示了HTTP_Request2::getURL方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendRequest
/**
* Make an OAI-PMH request. Throw an exception if there is an error;
* return a SimpleXML object on success.
*
* @param string $verb OAI-PMH verb to execute.
* @param array $params GET parameters for ListRecords method.
*
* @return DOMDocument Response as DOM
* @throws Exception
* @throws HTTP_Request2_LogicException
*/
protected function sendRequest($verb, $params = [])
{
// Set up the request:
$request = new HTTP_Request2($this->baseURL, HTTP_Request2::METHOD_GET, ['ssl_verify_peer' => false]);
$request->setHeader('User-Agent', 'RecordManager');
// Load request parameters:
$url = $request->getURL();
$params['verb'] = $verb;
$url->setQueryVariables($params);
$urlStr = $url->getURL();
if ($this->debugLog) {
file_put_contents($this->debugLog, date('Y-m-d H:i:s') . ' [' . getmypid() . "] Request:\n{$urlStr}\n", FILE_APPEND);
}
// Perform request and throw an exception on error:
for ($try = 1; $try <= $this->maxTries; $try++) {
$this->message("Sending request: {$urlStr}", true);
try {
$response = $request->send();
$code = $response->getStatus();
if ($code >= 300) {
if ($try < $this->maxTries) {
$this->message("Request '{$urlStr}' failed ({$code}), retrying in " . "{$this->retryWait} seconds...", false, Logger::WARNING);
sleep($this->retryWait);
continue;
}
$this->message("Request '{$urlStr}' failed: {$code}", false, Logger::FATAL);
throw new Exception("{$this->source}: Request failed: {$code}");
}
$responseStr = $response->getBody();
if ($this->debugLog) {
file_put_contents($this->debugLog, date('Y-m-d H:i:s') . ' [' . getmypid() . "] Response:\n" . "{$responseStr}\n\n", FILE_APPEND);
}
return $this->processResponse($responseStr, isset($params['resumptionToken']));
} catch (Exception $e) {
if ($try < $this->maxTries) {
$this->message("Request '{$urlStr}' failed (" . $e->getMessage() . "), retrying in {$this->retryWait} seconds...", false, Logger::WARNING);
sleep($this->retryWait);
continue;
}
throw new Exception("{$this->source}: " . $e->getMessage());
}
}
throw new Exception("{$this->source}: Request failed");
}
示例2: callXServer
/**
* Call MetaLib X-Server
*
* @param array $params URL Parameters
*
* @return string XML
* @throws Exception
*/
protected function callXServer($params)
{
$request = new HTTP_Request2($this->baseURL, HTTP_Request2::METHOD_GET, ['ssl_verify_peer' => false]);
$request->setHeader('User-Agent', 'RecordManager');
$url = $request->getURL();
$url->setQueryVariables($params);
$cleanUrl = preg_replace('/user_password=([^&]+)/', 'user_password=***', $url->getURL());
$this->_message("Sending request: {$cleanUrl}", true);
$response = $request->send();
$code = $response->getStatus();
if ($code >= 300) {
$this->_message("Request '{$url}' failed: {$code}", false, Logger::FATAL);
throw new Exception("Request failed: {$code}");
}
$this->_message("Request successful", true);
return $response->getBody();
}
示例3: retrieveFile
/**
* Fetch a file to be harvested
*
* @param string $filename File to retrieve
*
* @return string xml
* @throws Exception
*/
protected function retrieveFile($filename)
{
$request = new HTTP_Request2($this->baseURL . $filename, HTTP_Request2::METHOD_GET, ['ssl_verify_peer' => false]);
$request->setHeader('User-Agent', 'RecordManager');
$url = $request->getURL();
$urlStr = $url->getURL();
$this->message("Sending request: {$urlStr}", true);
// Perform request and throw an exception on error:
$response = null;
for ($try = 1; $try <= 5; $try++) {
try {
$response = $request->send();
} catch (Exception $e) {
if ($try < 5) {
$this->message("Request '{$urlStr}' failed (" . $e->getMessage() . "), retrying in 30 seconds...", false, Logger::WARNING);
sleep(30);
continue;
}
throw $e;
}
if ($try < 5) {
$code = $response->getStatus();
if ($code >= 300) {
$this->message("Request '{$urlStr}' failed ({$code}), retrying in " . "30 seconds...", false, Logger::WARNING);
sleep(30);
continue;
}
}
break;
}
$code = is_null($response) ? 999 : $response->getStatus();
if ($code >= 300) {
$this->message("Request '{$urlStr}' failed: {$code}", false, Logger::FATAL);
throw new Exception("Request failed: {$code}");
}
return $response->getBody();
}