0

I am trying to connect to an HTTP site (eg http://www.http2demo.io/) using a proxy. But i don't know why it work for a website like google (https) but not for a http website

$url = 'https://google.com'; // **If I replace google.com by http://www.http2demo.io/ or any http website it send me a 502 error**
$proxyauth = 'Flexxa:XWIUHY';
$proxy = '45.77.161.17';
$proxyPort = '505';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//proxy suport
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYPORT, $proxyPort);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
//https
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/27.0.1453.94 Safari/537.36");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);

$output = curl_exec($ch);   

if(curl_exec($ch) === false)
{
    echo 'Curl error: ' . curl_error($ch);
}
else
{
    echo 'Operation completed without any errors';
}

echo $output;

curl_close($ch);
?>

The first one work but not the other

K S
  • 1
  • 1
  • Does this answer your question? [Make HTTP/2 request with PHP](https://stackoverflow.com/questions/37140780/make-http-2-request-with-php) – miken32 Nov 13 '19 at 22:05
  • 1
    I'm assuming, since you're trying to visit a site called "http2demo.io", that you are expecting to connect with HTTP 2.0. This protocol requires HTTPS, and also requires configuration on the client side, as explained in the duplicate. Further, since you have a proxy in the mix I expect that would have to specifically support HTTP 2.0. – miken32 Nov 13 '19 at 22:08
  • It is quite plausible that your proxy doesn't allow `CURLOPT_HTTPPROXYTUNNEL` to a http site (port 80). Try removing that option... – Daniel Stenberg Nov 13 '19 at 22:29
  • If i remove `CURLOPT_HTTPPROXYTUNNEL` i get this message "502 Bad Gateway Host Not Found or connection failed" – K S Nov 20 '19 at 19:14

0 Answers0