2013-12-11 70 views
0

範例網站:http://web.de捲曲HTTP代碼爲404

在瀏覽器中:沒有任何問題

在捲曲工作:還給錯誤404沒有找到。

捲曲選項

$cookie_file_path = "/adm/cookie.txt"; 


$header[0]   = "Accept: text/html,application/xhtml+xml,application/xml,"; 
$header[0]   .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; 
$header[]   = "Cache-Control: max-age=0"; 
$header[]   = "Connection: keep-alive"; 
$header[]   = "Keep-Alive: 300"; 
$header[]   = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"; 
$header[]   = "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3"; 
$header[]   = "Pragma: "; 

$ch     = curl_init(); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); 
curl_setopt ($ch, CURLOPT_HEADER, 1); 
curl_setopt ($ch, CURLOPT_HTTPHEADER, $header); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt ($ch, CURLOPT_POST, 0); 
curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_SSLVERSION,3); 
curl_setopt ($ch, CURLOPT_ENCODING, ""); 
curl_setopt ($ch, CURLOPT_MAXREDIRS, 10); 
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie_file_path); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie_file_path); 
curl_setopt ($ch, CURLOPT_NOBODY, 0); 


curl_exec($ch); 

可能是什麼原因呢?

+0

也許$ url是空的?? ...在這一行curl_setopt($ ch,CURLOPT_URL,$ url); – Hackerman

+0

不,不是。當我回應它時,它給了我一個URL。另外,當我在終端中使用cURL時,它也可以工作 – Musterknabe

回答

0

假設您在PHP中定義了有效的URL。這可能是因爲你的瀏覽器設置爲通過代理工作,並且你的代碼中沒有curl。

Setting $ url =「http://web.de」;並運行代碼,最後一行更改爲var_dump(curl_exec($ ch));結果顯示如下:

string(188828) "HTTP/1.1 200 OK\r\nDate: Wed, 11 Dec 2013 14:05:25 GMT\r\nServer: Apache\r\nX-Frame-Options: deny\r\nExpires: Thu, 21 Feb 2013 11:25:14 GMT\r\nPragma: no-cache\r\nCache-Control: private, max-age=0, proxy-revalidate, no-store, no-cache, must-revalidate, public\r\nVary: User-Agent,Accept-Encoding\r\nX-Appserver: hp-webde-bs004\r\nContent-Type: text/html;charset=UTF-8\r\nContent-Encoding: gzip\r\nRTSS: 1-1250-1\r\nContent-Length: 27965\r\nSet-Cookie: SSLB=.1; path=/; domain=.web.de\r\nSet-Cookie: SSID=BgAJEh0O"... 

所以在你的捲髮代碼中,一切似乎都沒問題。

+0

嗯,這很奇怪。你也可以嘗試https://regalkontrolle.de?我在那裏得到一個301,但是捲曲也不會跟着位置。有些奇怪的事情正在發展。 – Musterknabe

+0

cURL正在獲得301。要使curl跟隨重定向,您需要添加:curl_setopt($ ch,CURLOPT_FOLLOWLOCATION,true); – kguest

0

我提出了以下測試:

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, 0);    
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  

$raw_data = curl_exec($ch); 
curl_close($ch); 

var_dump($raw_data); 

輸出:

string '<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de" data-toolbar-loggedin="false"> 
<head> 
<title>WEB.DE - E-Mail-Adresse kostenlos, FreeMail, De-Mail &amp; Nachrichten</title> 
<meta charset="utf-8"/> 
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/> 
<link rel="start" href="http://web.de/"/> 
<link rel="help" href="https://kundenservice.web.de/"/> 
<link rel="copyright" href="http://web.de/Impressum/"/> 
'... (length=187595) 
0

好像我發現的錯誤。這些現在是我的選擇。 completeUrl是預先檢查網站是否需要使用https或http的網址。似乎有一些問題ssl

curl_setopt($ch, CURLOPT_URL, $completeUrl); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_USERAGENT, getCustomUserAgent()); 
curl_setopt($ch, CURLOPT_HEADER, $header); 
curl_setopt($ch, CURLOPT_ENCODING, "gzip"); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt ($ch, CURLOPT_SSLVERSION,3); 
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie_file_path); 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie_file_path);`