Я пытаюсь подключиться к веб-сайту, используя CURL
с прокси на localhost
, используя Xampp.
Вот код CURL
:
<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 = '103.94.120.66:52131';
curl_setopt($curl, CURLOPT_PROXY, $proxy);
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" => $data, "info" => $info, "error" => $error);
echo '<pre>';
print_r($allInfo);
echo '
';
Я получаю 1 из 2 ошибок каждый раз, когда запускаю скрипт:
1
Array
(
[data] =>
[info] => Array
(
[url] => https://www.stubhub.com/
[content_type] =>
[http_code] => 0
[header_size] => 0
[request_size] => 225
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 56.437
[namelookup_time] => 0
[connect_time] => 0.296
[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] => 103.94.120.66
[certinfo] => Array
(
)
[primary_port] => 52131
[local_ip] => 192.168.1.25
[local_port] => 59947
)
[error] => Recv failure: Connection was reset
)
2- * * 1016
Array
(
[0] =>
[1] => Array
(
[url] => https://www.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 103.94.120.66 port 52131: Timed out
)
Я пытался добавить эту опцию:
curl_setopt($curl, CURLOPT_PROXYPORT, 443);
Тоже попробовал с тем же портом прокси:
curl_setopt($curl, CURLOPT_PROXYPORT, 52131);
Но все еще не работает.
Я получил прокси отсюда http://gimmeproxy.com/api/getProxy?supportsHttps=true&maxCheckPeriod=3600&protocol=http
Так что же сделать, чтобы это заработало?
Есть ли лучший API / библиотека для прокси или что-то не так с моим кодом?