无法通过PHP中的代理发出cURL请求

时间:2017-06-16 10:49:02

标签: php curl proxy

我正在尝试通过PHP中的代理发出cURL请求,但页面永远不会加载。如果我通过shell命令使用相同的代理,它可以很好地工作,我得到了响应。这是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命令(有效):

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"

0 个答案:

没有答案