【发布时间】:2018-02-07 16:05:40
【问题描述】:
我正在使用此代码:
#include <iostream>
#include <string>
#include <boost/asio.hpp>
int main()
{
boost::asio::ip::tcp::iostream s("www.a.com", "http");
if(!s)
std::cout << "Could not connect to www.a.com\n";
s << "GET /b.txt HTTP/1.0\r\n"
<< "Host: www.a.com\r\n"
<< "Accept: */*\r\n"
<< "Connection: close\r\n\r\n" ;
for(std::string line; getline(s, line); )
std::cout << line << '\n';
}
当然,我使用正确的网站而不是“a.com” 但我总是收到“无法连接到 www.a.com” 知道为什么吗?
【问题讨论】:
-
s.error().message()说什么? -
无法连接到 www.a.com HTTP/1.1 400 错误请求日期:2018 年 2 月 7 日星期三 16:15:35 GMT 服务器:Apache 接受范围:字节变化:接受编码,用户代理连接:关闭内容类型:text/html
-
如果使用有效地址会怎样?
-
请发布您尝试连接的网址。
标签: c++ boost-asio