我需要通过https代理从我的PHP代码发送请求。 我已经尝试了,无论如何我可以考虑PHP CURL,http_request2,file_get_content,但没有任何运气。
我实际上需要翻译curl命令:
curl -x https://127.0.0.1:8089 https://api.ipify.org?format=json
必须是https代理
以PHP方式(没有exec,系统等...)
有任何想法吗?
答案 0 :(得分:0)
Hello, i found this function, it's very useful,and doesnot check the SSL certificate (good for you) :
<code>
/**
* Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an
* array containing the HTTP server response header fields and content.
*/
function get_web_page( $url )
{
$options = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "spider", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_SSL_VERIFYPEER => false // Disabled SSL Cert checks
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
return $header;
}
</code>
答案 1 :(得分:0)
您可以将curl与代理一起使用,而不会出现任何问题。
您可以使用一些配置选项来实现您的目标。其中一个是CURLOPT_PROXY 您可以在此处查看所有选项以配置代理:http://php.net/manual/pt_BR/function.curl-setopt.php