2013-12-11 69 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);`