2012-07-14 133 views
0

我的問題是兩種不同的響應。相同的請求不同的響應

我的代碼的一部分發送請求。

boost::asio::ip::tcp::iostream stream; 
stream.expires_from_now(boost::posix_time::seconds(60)); 
stream.connect("www.mail.ru","http"); 
stream << "GET /cgi-bin/msglist HTTP/1.1\r\n"; 
stream << "Host: e.mail.ru\r\n"; 
stream << "Connection: keep-alive\r\n"; 
stream << "User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11\r\n"; 
stream << "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"; 
stream << "Referer: http://mail.ru/ \r\n"; 
stream << "Accept-Encoding: gzip,deflate,sdch\r\n"; 
stream << "Accept-Language: en-US,en;q=0.8\r\n"; 
stream << "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3\r\n"; 
stream << "Cookie: Cookie here \r\n\r\n"; 


Such a response from the server I get from the code 

HTTP/1.1 302 OK 

Date: Fri, 13 Jul 2012 19:00:06 GMT 

Server: Apache/1.3.27 (Unix) mru_xml/0.471 gorgona/2.1 mod_jk/1.2.4 mod_ruby/1.0.7 Ruby/1.6.8 mod_mrim/0.17 

Connection: close 

Location: http://e.mail.ru/cgi-bin/msglist 

Content-Length: 0 

Content-Type: text/plain 

但是,當我從我的標題相同的瀏覽器做同樣的要求我,我得到

這種反應

//HTTP/1.1 200 OK 
//Server: nginx/0.7.62 
//Date: Fri, 13 Jul 2012 18:50:46 GMT 
///Content-Type: text/html; charset=utf-8 
//Connection: close 
//P3P: CP="NON CUR OUR IND UNI INT" 
//Cache-Control: no-cache,no-store,must-revalidate 
//Pragma: no-cache 
//Expires: Thu, 14 Jul 2011 18:50:46 GMT 
//Last-Modified: Fri, 13 Jul 2012 22:50:46 GMT 
//X-Host: f306.mail.ru 
//Content-Length: 461042 

等什麼錯我的代碼?(我需要得到響應200我的代碼)

+0

您的代碼在完成之前停止。你有一個302,剛剛停下來。你需要繼續前進,直到你得到200.解析迴應並決定下一步該做什麼。 – 2012-07-14 12:32:34

回答

1

找到302,在位置有重定向鏈接。 http://en.wikipedia.org/wiki/HTTP_302 您應該從位置獲取網址並向該網址發送其他請求。

+0

嗯,我沒有得到它)​​即時通訊allredy試圖請求網址 – user1515777 2012-07-14 14:16:41

+0

@ user1515777看看大衛施瓦茨的評論。 – ForEveR 2012-07-14 14:23:05

相關問題