doudou0111 2018-10-29 19:53 采纳率: 0%
浏览 653

如何为https网站选择CURL代理?

I'm trying to connect to a website using CURL on localhost, I tried many proxies but most of them didn't work.

Here is the code:

$url= 'https://stubhub.com';
$curl = curl_init();
curl_setopt( $curl, CURLOPT_URL, $url );
curl_setopt($curl, CURLOPT_REFERER, $url);
curl_setopt( $curl, CURLOPT_AUTOREFERER, TRUE );
curl_setopt( $curl, CURLOPT_HEADER, FALSE );
curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 0 );
curl_setopt( $curl, CURLOPT_TIMEOUT, 0 );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, TRUE );
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

//certificate
$cacert='C:/xampp/cacert.pem';
curl_setopt( $curl, CURLOPT_CAINFO, $cacert );

//SSL
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);

//Cookies
curl_setopt($curl, CURLOPT_COOKIEFILE,__DIR__."/cookie.txt");

//User-Agent
curl_setopt( $curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36' );

//Proxy
$proxy = '50.115.194.97:8080';
curl_setopt($curl, CURLOPT_PROXY, $proxy);
curl_setopt($curl, CURLOPT_PROXYPORT, 443);
curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, TRUE);


//Errors
curl_setopt($curl, CURLOPT_VERBOSE, TRUE);

$data = curl_exec( $curl );
$info = curl_getinfo( $curl );
$error = curl_error( $curl );
curl_close( $curl );

$allInfo = array($data, Info, $error);
echo '<pre>';
print_r($allInfo);
echo '</pre>';

I get the following response:

Array
(
    [0] => 
    [1] => Array
        (
            [url] => https://stubhub.com/
            [content_type] => 
            [http_code] => 0
            [header_size] => 0
            [request_size] => 0
            [filetime] => -1
            [ssl_verify_result] => 0
            [redirect_count] => 0
            [total_time] => 20.203
            [namelookup_time] => 0
            [connect_time] => 0
            [pretransfer_time] => 0
            [size_upload] => 0
            [size_download] => 0
            [speed_download] => 0
            [speed_upload] => 0
            [download_content_length] => -1
            [upload_content_length] => -1
            [starttransfer_time] => 0
            [redirect_time] => 0
            [redirect_url] => 
            [primary_ip] => 
            [certinfo] => Array
                (
                )

            [primary_port] => 0
            [local_ip] => 
            [local_port] => 0
        )

    [2] => Failed to connect to 50.115.194.97 port 8080: Timed out
)

I tried with proxies that supports https, cookies and those with 443 port.

Is there is an API/library for this purpose?

  • 写回答

2条回答 默认 最新

  • doucha4054 2018-10-29 20:42
    关注

    You can use any of open proxy apis.

    For example: gimmeproxy.com/api/getProxy?post=true&supportsHttps=true&maxCheckPeriod=7200&protocol=http

    It looks like the proxy you are trying to use is down (not working).

    As for me, I built the proxy parser and agregator for our projects. It is getting proxies from a bunch of open proxy lists, saves them to the database and checks them in the loop. It became a very useful tool for us.

    评论

报告相同问题?

悬赏问题

  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加