本文整理汇总了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);
?>