I need to send requests from my PHP code through https proxy. I already tried, anyway I can think about with the PHP CURL, http_request2, file_get_content, but without any luck.
I actually need to translate the curl command: curl -x https://127.0.0.1:8089 https://api.ipify.org?format=json
must be https proxy To PHP way (without the exec, system, etc...) Any ideas?
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>
You can use curl with proxies with no problems at all.
There is some configuration options that you can use to achieve what you want. One of them is CURLOPT_PROXY You can checkout all options to configure the proxy here: http://php.net/manual/pt_BR/function.curl-setopt.php
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.