本文整理匯總了PHP中http::use_proxy方法的典型用法代碼示例。如果您正苦於以下問題:PHP http::use_proxy方法的具體用法?PHP http::use_proxy怎麽用?PHP http::use_proxy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類http
的用法示例。
在下文中一共展示了http::use_proxy方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getHttpRetriever
function getHttpRetriever($path)
{
//Including depends
if (!class_exists("http")) {
if (defined('LIB_HTTP_PATH')) {
require_once LIB_HTTP_PATH . "/http.php";
}
}
$httpClient = new http(HTTP_V11, false);
$parsedUrl = parse_url($path);
$httpClient->host = isset($parsedUrl['host']) ? $parsedUrl['host'] : $this->host;
$httpClient->port = isset($parsedUrl['port']) ? $parsedUrl['port'] : 80;
$path = $parsedUrl['path'] . (isset($parsedUrl['query']) ? '?' . $parsedUrl['query'] : '');
$proxySettings = isset($this->_websites_config[$this->host]['proxy']) ? $this->_websites_config[$this->host]['proxy'] : $this->_websites_config['default']['proxy'];
if ($proxySettings) {
$parsedUrl = parse_url($proxySettings);
$httpClient->use_proxy($parsedUrl['host'], $parsedUrl['port'], $parsedUrl['user'], $parsedUrl['pass']);
}
if (isset($this->_websites_config['default']['user_agent'])) {
$httpClient->user_agent = $this->_websites_config['default']['user_agent'];
}
if (isset($this->_websites_config[$this->host]['user_agent'])) {
$httpClient->user_agent = $this->_websites_config[$this->host]['user_agent'];
}
$connectionTimeout = isset($this->_websites_config[$this->host]['connection_timeout']) ? $this->_websites_config[$this->host]['connection_timeout'] : (isset($this->_websites_config['default']['connection_timeout']) ? $this->_websites_config['default']['connection_timeout'] : 30);
$httpClient->connection_timeout = $connectionTimeout;
return $httpClient;
}
示例2: http
<?php
/*********************************************************************
* Demonstrates the use of requests via proxy
*********************************************************************/
header('Content-Type: text/plain');
require_once 'http.inc';
$http_client = new http(HTTP_V11, false);
$http_client->host = 'www.yahoo.com';
$http_client->use_proxy('ns.crs.org.ni', 3128);
if ($http_client->get('/') == HTTP_STATUS_OK) {
print_r($http_client);
} else {
print 'Server returned ' . $http_client->status;
}
unset($http_client);
?>