本文整理汇总了PHP中eZHTTPTool::sendHTTPRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP eZHTTPTool::sendHTTPRequest方法的具体用法?PHP eZHTTPTool::sendHTTPRequest怎么用?PHP eZHTTPTool::sendHTTPRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eZHTTPTool
的用法示例。
在下文中一共展示了eZHTTPTool::sendHTTPRequest方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSendRequestContainingDashes
/**
* If you send an HTTP request using eZHTTPTool::sendHTTPRequest( ) to an
* URL with a domain name containing a dash ( -), it's misunderpreted and
* doesn't get executed.
*
* @link http://issues.ez.no/10651
*/
public function testSendRequestContainingDashes()
{
self::markTestSkipped( "Test disabled pending update." );
$url = 'http://php-og.mgdm.net/';
$this->assertInternalType(
PHPUnit_Framework_Constraint_IsType::TYPE_STRING,
eZHTTPTool::sendHTTPRequest( $url, 80, false, 'eZ Publish', false )
);
}
示例2: requestRates
function requestRates()
{
$error = array('code' => self::OK, 'description' => ezpI18n::tr('kernel/shop', "'Autorates' were retrieved successfully"));
$serverName = $this->serverName();
$serverPort = $this->serverPort();
$ratesURI = $this->ratesURI();
$ratesList = array();
$buf = eZHTTPTool::sendHTTPRequest("{$serverName}/{$ratesURI}", $serverPort, false, 'eZ Publish', false);
if ($buf) {
$header = false;
$body = false;
if (eZHTTPTool::parseHTTPResponse($buf, $header, $body)) {
if ($header['content-type'] === 'text/xml') {
// parse xml
$dom = new DOMDocument('1.0', 'utf-8');
$dom->preserveWhiteSpace = false;
$success = $dom->loadXML($body);
$xpath = new DOMXPath($dom);
$xpath->registerNamespace('eurofxref', 'http://www.ecb.int/vocabulary/2002-08-01/eurofxref');
$rootNode = $dom->documentElement;
$cubeNode = $xpath->query('eurofxref:Cube', $rootNode)->item(0);
$timeNode = $cubeNode->firstChild;
foreach ($timeNode->childNodes as $currencyNode) {
$currencyCode = $currencyNode->getAttribute('currency');
$rateValue = $currencyNode->getAttribute('rate');
$ratesList[$currencyCode] = $rateValue;
}
} else {
$error['code'] = self::FAILED;
$error['description'] = ezpI18n::tr('kernel/shop', "Unknown body format in HTTP response. Expected 'text/xml'");
}
} else {
$error['code'] = self::FAILED;
$error['description'] = ezpI18n::tr('kernel/shop', "Invalid HTTP response");
}
} else {
$error['code'] = self::FAILED;
$error['description'] = ezpI18n::tr('kernel/shop', "Unable to send http request: %1:%2/%3", null, array($serverName, $serverPort, $ratesURI));
}
$this->setRateList($ratesList);
return $error;
}
示例3: downloadFile
/**
* Downloads file.
*
* Sets $this->ErrorMsg in case of an error.
*
* \private
* \param $url URL.
* \param $outDir Directory where to put downloaded file to.
* \param $forcedFileName Force saving downloaded file under this name.
* \return false on error, path to downloaded package otherwise.
*/
function downloadFile($url, $outDir, $forcedFileName = false)
{
$fileName = $outDir . "/" . ($forcedFileName ? $forcedFileName : basename($url));
eZDebug::writeNotice("Downloading file '{$fileName}' from {$url}");
// Create the out directory if not exists.
if (!file_exists($outDir)) {
eZDir::mkdir($outDir, false, true);
}
// First try CURL
if (extension_loaded('curl')) {
$ch = curl_init($url);
$fp = eZStepSiteTypes::fopen($fileName, 'wb');
if ($fp === false) {
$this->ErrorMsg = ezpI18n::tr('design/standard/setup/init', 'Cannot write to file') . ': ' . $this->FileOpenErrorMsg;
return false;
}
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
// Get proxy
$ini = eZINI::instance();
$proxy = $ini->hasVariable('ProxySettings', 'ProxyServer') ? $ini->variable('ProxySettings', 'ProxyServer') : false;
if ($proxy) {
curl_setopt($ch, CURLOPT_PROXY, $proxy);
$userName = $ini->hasVariable('ProxySettings', 'User') ? $ini->variable('ProxySettings', 'User') : false;
$password = $ini->hasVariable('ProxySettings', 'Password') ? $ini->variable('ProxySettings', 'Password') : false;
if ($userName) {
curl_setopt($ch, CURLOPT_PROXYUSERPWD, "{$userName}:{$password}");
}
}
if (!curl_exec($ch)) {
$this->ErrorMsg = curl_error($ch);
return false;
}
curl_close($ch);
fclose($fp);
} else {
$parsedUrl = parse_url($url);
$checkIP = isset($parsedUrl['host']) ? ip2long(gethostbyname($parsedUrl['host'])) : false;
if ($checkIP === false) {
return false;
}
// If we don't have CURL installed we used standard fopen urlwrappers
// Note: Could be blocked by not allowing remote calls.
if (!copy($url, $fileName)) {
$buf = eZHTTPTool::sendHTTPRequest($url, 80, false, 'eZ Publish', false);
$header = false;
$body = false;
if (eZHTTPTool::parseHTTPResponse($buf, $header, $body)) {
eZFile::create($fileName, false, $body);
} else {
$this->ErrorMsg = ezpI18n::tr('design/standard/setup/init', 'Failed to copy %url to local file %filename', null, array("%url" => $url, "%filename" => $fileName));
return false;
}
}
}
return $fileName;
}
示例4: testSendRequestContainingDashes
/**
* If you send an HTTP request using eZHTTPTool::sendHTTPRequest( ) to an
* URL with a domain name containing a dash ( -), it's misunderpreted and
* doesn't get executed.
*
* @link http://issues.ez.no/10651
*/
public function testSendRequestContainingDashes()
{
$url = 'http://php-og.mgdm.net/';
$this->assertType(PHPUnit_Framework_Constraint_IsType::TYPE_STRING, eZHTTPTool::sendHTTPRequest($url, 80, false, 'eZ Publish', false));
}