如何为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?

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.

要为HTTPS网站选择CURL代理,可以按照以下步骤:

确认你的CURL版本支持HTTPS协议。可以在命令行窗口输入 curl -V 查看。

找到一个可用的HTTPS代理服务器,可以选择一个付费的或免费的代理服务器。

配置CURL代理,可以在命令行窗口中使用以下命令:

curl -x <代理服务器地址>:<代理服务器端口号> <目标网站地址>

例如,要访问https://www.example.com网站并使用代理服务器,可以输入以下命令:

curl -x proxy.example.com:8080 https://www.example.com/

其中,proxy.example.com是代理服务器地址,8080是代理服务器端口号,https://www.example.com是目标网站地址。

如果代理服务器需要身份验证,可以添加以下命令:
curl -x <代理服务器地址>:<代理服务器端口号> -U <用户名>:<密码> <目标网站地址>

例如,要访问https://www.example.com网站并使用需要身份验证的代理服务器,可以输入以下命令:

curl -x proxy.example.com:8080 -U username:password https://www.example.com/

其中,username是代理服务器的用户名,password是代理服务器的密码。

这样就可以使用CURL代理访问HTTPS网站了。