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 如何提取csv文件中需要的列,将其整合为一篇完整文档,并进行jieba分词(语言-python)
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?