I am trying to make a cURL request through a proxy in PHP but the page never loads. If I use the same proxy via shell commands it works perfectly and I get the response. Here's the code on PHP:
$url = "https://example.com"
$myvars = "key1=value1&key2=value2;
$ch = curl_init( $url );
curl_setopt($ch, CURLOPT_PROXY, '172.93.148.247');
curl_setopt($ch, CURLOPT_PROXYPORT, '3128');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded; charset=utf-8'
));
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
Shell command (works):
curl --proxy 172.93.148.247:3128 -v -X POST 'https://example.com' -H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' -H 'Cookie:' -d "key1=value1&key2=value2"