user3079266
user3079266

Reputation:

PHP connect to HTTPS site through proxy

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

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

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.

Upvotes: 2

Views: 14814

Answers (1)

Pascal Le Merrer
Pascal Le Merrer

Reputation: 5981

Update: Add

curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);

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


initial answer, not interesting

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.

Upvotes: 2

Related Questions