【发布时间】:2018-08-01 05:18:12
【问题描述】:
我在连接网络代理时遇到了很多麻烦。我已经尝试了几种设置,但都没有奏效。即使我已经进行了身份验证,最近的一个也返回了“HTTP/1.1 407 Proxy Authentication Required [Proxy-Authenticate]”错误。
这是我正在使用的代码:
<?php
// Edit the four values below
$PROXY_HOST = "proxy.det.nsw.edu.au"; // Proxy server address
$PROXY_PORT = "8080"; // Proxy server port
$PROXY_USER = "USERNAME"; // Username
$PROXY_PASS = "PASSWORD"; // Password
// Username and Password are required only if your proxy server needs basic authentication
$auth = base64_encode("$PROXY_USER:$PROXY_PASS");
stream_context_set_default(
array(
'http' => array(
'proxy' => "tcp://$PROXY_HOST:$PROXY_PORT",
'request_fulluri' => true,
'header' => "Proxy-Authorization: Basic $auth"
// Remove the 'header' option if proxy authentication is not required
)
)
);
$targetURL = "http://stackoverflow.com/questions/17111112/using-get-headers-with-a-proxy";
print_r(get_headers($targetURL, 1));
echo ("<br><br>");
$result = file_get_contents($targetURL);
?>
这是代理的返回:
Array ( [0] => HTTP/1.1 407 需要代理身份验证 [代理验证] => 数组([0] => NEGOTIATE [1] => NTLM) [Cache-Control] => 无缓存 [Pragma] => 无缓存 [Content-Type] => 文本/html; charset=utf-8 [代理连接] => 关闭 [Set-Cookie] => BCSI-CS-47afdfff6410962d=2;路径=/ [连接] => 关闭 [内容长度] => 653 )
警告: 文件获取内容(http://stackoverflow.com/questions/17111112/using-get-headers-with-a-proxy): 无法打开流:HTTP 请求失败! HTTP/1.1 407 代理 C:\inetpub\wwwroot\sites\phpProxyTest.php 中需要身份验证 第 36 行
如果有帮助,我会尝试针对代理对用户进行身份验证,以查看他们是否是有效用户,因此我只需要来自代理的 Yes/No 响应。不幸的是,我无权访问管理员登录或代理的任何其他部分,因此无法直接获取用户。任何帮助将不胜感激,如果您需要更多信息,请询问。
【问题讨论】:
标签: php proxy network-programming basic-authentication http-proxy