CURL 및 리디렉션CURL 및 리디렉션
안녕.
일부 사이트를 확인하는 데 CURL을 사용하고 있습니다. 일부 리디렉션에 문제가 있습니다. 매번이 아니라 단지 몇 가지 경우입니다.
이 경우 302 코드가 있지만 리디렉션 URL은 원래 URL과 같습니다. CURL 변수의
덤프 :
array(23) {
["url"]=> string(33) "http://www.apostasurpresa.gov.br/"
["content_type"]=> string(24) "text/html; charset=UTF-8"
["http_code"]=> int(302)
["header_size"]=> int(180)
["request_size"]=> int(92)
["filetime"]=> int(-1)
["ssl_verify_result"]=> int(0)
["redirect_count"]=> int(0)
["total_time"]=> float(0.037685)
["namelookup_time"]=> float(0.000171)
["connect_time"]=> float(0.018808)
["pretransfer_time"]=> float(0.01882)
["size_upload"]=> float(0)
["size_download"]=> float(0)
["speed_download"]=> float(0)
["speed_upload"]=> float(0)
["download_content_length"]=> float(0)
["upload_content_length"]=> float(0)
["starttransfer_time"]=> float(0.037521)
["redirect_time"]=> float(0)
["redirect_url"]=> string(33) "http://www.apostasurpresa.gov.br/"
["primary_ip"]=> string(15) "200.201.166.106"
["certinfo"]=> array(0) { } }
컬 페이지 :
$ch = curl_init();
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,60);
curl_setopt($ch, CURLOPT_COOKIESESSION , 1);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST ,'GET');
// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HEADER, 1); // true
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_POSTREDIR, 6);// 3 => 6
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // false
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
$txt_pagina = curl_exec($ch);
$info=curl_getinfo($ch);
curl_close($ch);
감사
나는 curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 0)을 시도했다; 과 동일한 결과가있는 curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1). – RSLyra
브라우저에서 페이지를 방문하면 어떻게됩니까? 서버가 사용자 에이전트에 만족스럽지 않고 따라서 루프로 다시 리디렉션 될 수 있다고 생각합니까? "실제"브라우저의 사용자 에이전트 문자열을 사용해보십시오 ... – ivanivan
http://loterias.caixa.gov.br/wps/portal/loterias/로 리디렉션하십시오. – RSLyra