我试图用C ++和Boost制作一个Http-Request。这是一个片段:
std::string request;
[..]
this->request_ = "GET / HTTP/1.1\r\n"
"Host: api.poloniex.com\r\n"
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
"Accept-Language: de,en-US;q=0.7,en;q=0.3\r\n"
"Accept-Encoding: gzip, deflate\r\n"
"Sec-WebSocket-Version: 13\r\n"
"Sec-WebSocket-Protocol: wamp.2.json\r\n"
"Sec-WebSocket-Extensions: permessage-deflate\r\n"
"Sec-WebSocket-Key: czW+w3Z+3yZCKVGx6DQ1Rg==\r\n"
"Connection: keep-alive, Upgrade\r\n"
"Pragma: no-cache\r\n"
"Cache-Control: no-cache\r\n"
"Upgrade: websocket\r\n\r\n";
size_t request_length = request_.length();
boost::asio::async_write(socket_, boost::asio::buffer(request_.c_str(), request_length), boost::bind(&client::handle_write, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
问题是另一端的服务器无法识别Http-Header的结尾,因此无法应答。当我尝试使用openssl s_client -connect api.poloniex.com:443
手动发出请求然后发送标头时,我遇到了同样的问题。服务器无法识别结束。我不得不使用-crlf
标志,其定义如下:
-crlf - 将LF从终端转换为CRLF
如何使用字符串正确发送CRLF?
编辑:更换所有" \ r \ n"用" \ x0D \ x0A"也行不通。