2012-07-14 104 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

相关问题