2017-09-05 192 views
0

我需要通过https代理从我的PHP代码发送请求。 我已经试过了,无论如何,我可以考虑PHP CURL,http_request2,file_get_content,但没有任何运气。通过https代理发送curl请求

其实我需要翻译curl命令: curl -x https://127.0.0.1:8089 https://api.ipify.org?format=json 必须是HTTPS代理 到PHP的方式(不包括高管,系统,等...) 任何想法?

+0

您是否_search_? – undefined

+0

你检查了这个线程吗? [链接](https://stackoverflow.com/questions/9445489/performing-http-requests-with-curl-using-proxy) –

+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> 
+0

你不在脚本中使用代理...我必须通过我的代理 –

0

您可以在所有使用与代理卷曲,没有任何问题。

有一些配置选项可以用来实现你想要的。其中之一是CURLOPT_PROXY 您可以结算所有选项来配置代理服务器:http://php.net/manual/pt_BR/function.curl-setopt.php

+0

Php curl无法处理https代理,只有http代理 –