【问题标题】:How to connect to a secure (https) proxy with curl and php?如何使用 curl 和 php 连接到安全 (https) 代理?
【发布时间】:2015-12-06 01:45:20
【问题描述】:

现代浏览器支持可通过 PAC 文件连接的 HTTPS 代理(如果您不熟悉,请参阅 https://www.igvita.com/2012/06/25/spdy-and-secure-proxy-support-in-google-chrome/)。

我正在尝试复制相同的内容并通过 php CURL 连接到这样的代理,但我只是得到一个空白响应,没有标题或内容。

我的代码如下:

$url = "http://checkip.dyndns.com";
$proxy = "proxy.domain.com:443";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL , 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'test:test');
curl_setopt($ch, CURLOPT_PROXYTYPE, "CURLPROXY_HTTP");
$response = curl_exec($ch);
curl_close($ch);

echo $response;

有什么想法吗?

【问题讨论】:

标签: php curl proxy


【解决方案1】:

如果有人感兴趣,解决方法是使用 spdycat 代替 curl:https://github.com/tatsuhiro-t/spdylay

【讨论】:

    【解决方案2】:

    目前尚不支持通过 HTTPS 与 curl 连接到代理。不过 git 中有一个正在进行中的分支:https://github.com/bagder/curl/tree/HTTPS-proxy

    我们将感谢您帮助我们将其合并。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-13
      • 2015-11-15
      • 1970-01-01
      • 2019-07-22
      • 2015-02-05
      • 2020-02-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多