如何使用curl和php连接到安全(https)代理?

问题描述:

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

Modern browsers support HTTPS proxies that can be connected to via a PAC file (see https://www.igvita.com/2012/06/25/spdy-and-secure-proxy-support-in-google-chrome/ if you're not familiar).

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

I'm trying to replicate the same thing and connect to such a proxy via php CURL, but I'm simply getting a blank response, no headers or content.

我的代码如下:

$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;

任何想法?

不支持使用curl连接到带有HTTPS的代理。在git中有一个正在进行中的分支: https://github.com/ bagder / curl / tree / HTTPS-proxy

There's no support for connecting to a proxy with HTTPS with curl yet. There is a work-in-progress branch in git though: https://github.com/bagder/curl/tree/HTTPS-proxy

我们非常感谢您帮助我们成功合并。

We will appreciate help to get that in shape to merge.