2012-08-29 2 views
2

때때로 작동하는이 cUrl 요청을 받았고 작동을 멈췄습니다. 나는 HTTP가 확인 200없이 오류를 표시하지만 콘텐츠 길이가 0PHP cUrl 0 콘텐츠 길이, 오류 없음

$userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)'; 
$cslbnum = "881126"; 
$target_url =  "https://www2.somewebsite.aspx?LicNum=" . $cslbnum; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent); 
curl_setopt($ch, CURLOPT_REFERER, "https://www2.somesite.aspx"); 
curl_setopt($ch, CURLOPT_URL,$target_url); 
curl_setopt($ch, CURLOPT_FAILONERROR, true); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); 
curl_setopt($ch, CURLOPT_AUTOREFERER, true); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); 
curl_setopt($ch, CURLOPT_TIMEOUT, 100); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
if(curl_exec($ch) === false) 
{ 
echo 'Curl error: ' . curl_error($ch); 
} 
else 
{ 
echo 'Operation completed without any errors'; 
} 
$html = curl_exec($ch); 
$html = @mb_convert_encoding($html, 'HTML-ENTITIES', 'utf-8'); 
curl_close($ch); 

echo $html; 

어떤 아이디어가 무엇을이 원인이 될 수있다, 헤더와 오류를 울리는 무엇입니까? 오늘 아침에 맹세 컨대 나는 일했다고 생각하고 직장에서 집에 왔어. 사이트를 직접 테스트하여 정상적으로 작동합니다.

답변

2

코드의 마지막 비트입니다. curl_exec을 두 번 호출합니다.

// ... 
$html = curl_exec($ch); 
if($html === false) 
{ 
echo 'Curl error: ' . curl_error($ch); 
} 
else 
{ 
echo 'Operation completed without any errors'; 
} 
$html = @mb_convert_encoding($html, 'HTML-ENTITIES', 'utf-8'); 
curl_close($ch); 
echo $html; 

또한 @을 피하십시오.

+0

고마워, 나는 그것을 붙잡고 싶지 않았다. 나는 이것을 몇 시간 씩 어루 만져왔다. 콘텐츠 길이가 0이고 페이지가 표시되지 않는 경우 매우 불쾌합니다. – savagenoob

+0

@savagenoob URL이'https : //www2.somewebsite.com/default.aspx? LicNum ='입니까? –

+0

아니요.하지만 포럼에 게시하고 싶지 않습니다. 보내실 수있는 방법은 여기에 있습니까? 어쩌면 개인 이메일? – savagenoob