【问题标题】:PHP cannot authenticate with proxy even with "Proxy-Authorization: Basic"即使使用“代理授权:基本”,PHP 也无法使用代理进行身份验证
【发布时间】: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


    【解决方案1】:

    HTTP 中对代理的身份验证由代理的配置控制。

    在您的情况下,代理仅宣传对 NEGOTIATE 和 NTLM 的支持,因此不接受基本发送。

    您还说您“已通过身份验证”,但这不是您的电话。如果您之前已通过代理验证(例如使用 Web 浏览器),它可能会认为您已通过验证,或者它可能要求与代理的每个连接都经过验证。

    您需要使用 NTLM 或 NEGOTIATE 来通过该代理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-30
      • 2017-11-24
      • 2019-01-31
      • 2013-05-30
      • 2013-06-03
      相关资源
      最近更新 更多