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)

4

1 回答 1

1

找到 302,在 location 有重定向链接。http://en.wikipedia.org/wiki/HTTP_302 您应该从位置获取 url 并对这个 url 发出其他请求。

于 2012-07-14T12:25:34.203 回答