PHP通过代理连接到HTTPS站点 [英] PHP connect to HTTPS site through proxy

查看:118
本文介绍了PHP通过代理连接到HTTPS站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了以下问题:有一个HTTPS网站,我需要通过代理连接到它。以下是我的cURL setopts:

I've got the following problem: there is an HTTPS web site, and I need to connect to it through a proxy. Here are my cURL setopts:

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, '100.100.100.100:8080');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

echo curl_error($ch);

输出连接到######。com:8080;无错误

outputs Failed connect to ######.com:8080; No error

其中100.100.100.100:8080是有效HTTPS代理的占位符。这不起作用。如何通过代理使cURL连接到HTTPS网站?我真的很想要一个不仅可以通过HTTPS代理工作的灵魂。另外,我最喜欢使用cURL的方法,但是如果有更好的方法,没有cURL,我可以改用它。

Where 100.100.100.100:8080 is a placeholder for a valid HTTPS proxy. This doesn't work. How do I make cURL connect to an HTTPS website through a proxy? I would really like a soultion that would work through not only HTTPS proxies. Also, I would best prefer a method using cURL, but if there is a better way to do it, without cURL, I could use it instead.

推荐答案

更新:
添加

curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);

它将阻止您的HTTP代理解析您的请求标头并采取更透明的行为 - 就像隧道一样。

It will prevent your HTTP proxy to parse your request headers and to act more transparently - like a tunnel.

初步回答,不感兴趣

您的代码看起来不错,我假设您检查了琐碎的问题,因此问题可能是SSL证书验证失败。如果证书是通过示例自签名的话就是这种情况。
尝试

Your code looks OK, and I assume you checked the trivial issues, so the problem is probably that the SSL certificate verification fails. It's the case if the certificate is self signed by example. Try

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

允许允许使用自签名证书的请求。

to allow a request that allows using a self signed certificate.

这篇关于PHP通过代理连接到HTTPS站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆