简体   繁体   English

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

[英]How to connect to a secure (https) proxy with curl and php?

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

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. 我正在尝试复制相同的东西并通过php CURL连接到这样的代理,但我只是得到一个空白的响应,没有标题或内容。

My code is as follows: 我的代码如下:

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

Any ideas? 有任何想法吗?

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

There's no support for connecting to a proxy with HTTPS with curl yet. 目前还不支持使用带curl的HTTPS连接代理。 There is a work-in-progress branch in git though: https://github.com/bagder/curl/tree/HTTPS-proxy git中有一个正在进行中的分支: https//github.com/bagder/curl/tree/HTTPS-proxy

We will appreciate help to get that in shape to merge. 我们将非常感谢能够帮助您实现合并。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM