Boost ASIO:文档不完整
Boost ASIO : Document not complete
我正在为Boost ASIO套接字侦听器使用以下模板代码:
#include <iostream>
#include <string>
#include <boost/asio.hpp>
using boost::asio::ip::tcp;
int main()
{
try
{
boost::asio::io_service io_service;
tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v4(), 88));
for (;;)
{
tcp::socket socket(io_service);
acceptor.accept(socket);
std::string message = "<!DOCTYPE html><html><body><h1>HELLO WORLD</h1></body></html>";
boost::system::error_code ignored_error;
boost::asio::write(socket, boost::asio::buffer(message), boost::asio::transfer_all(), ignored_error);
}
} catch (std::exception& e) { std::cerr << e.what() << std::endl; }
return 0;
}
当我在浏览器中查看它时,它运行良好。
但当我试图从另一个应用程序(如Node.JS中的HTTP.request)中读取它时,它失败了,并出现解析错误。如果我通过https://validator.w3.org,上面写着"I/O错误:由于非文档错误,无法确定结果"。
请参阅HTTP规范(RFC7230)第19页第3节
HTTP消息的格式为:
HTTP-message = start-line
*( header-field CRLF )
CRLF
[ message-body ]
进一步阅读将揭示起始行的限制和要求、标题的格式以及向接收方指示消息正文长度的要求(或在分块消息的情况下检测它的方法)
上面的代码格式如下:
[ message-body ]
相关文章:
- 正在查找文档以获得PS4平台的C++中的设备信息
- 如何在文档文件夹中创建目录
- 当Microsoft文档仅包含 C# 示例时,如何查找 C++ 包含文件名
- 通过构造函数创建一些值并尝试添加到文档中使用 rapidjson 不起作用
- 关于类的 Python 文档 - 对C++的引用不正确
- C++/autoconf 等效于文档库要求.txt的要求是什么?
- mbed:使用 USB 文档库编译会导致错误
- C++ VISUAL STUDIO:GLFWwindow没有初始化,即使它是在文档中编写的并且以前工作过
- 使用 yaml-cpp 更新 YAML 文档的节点和值
- 在加载 MSHTML 文档之前从 MSHTML 文档中删除无效的 URL
- 如何在C++中表示JSON文档的递归对象结构?
- 如何查找 Redshift Maya API 文档?
- 如何使用值模板编写文档测试用例?
- 如何使用 Gradle DSL(领域特定语言)上的文档?
- ncurses 找不到任何关于cchar_t的文档
- 提取狮身人面像文档中的C++代码片段
- 关于 API 文档和设备操作 在助手-sdk-cpp 上
- 如何搜索提升文档?
- 使用 mongo c++ 驱动程序查询嵌套的 BSON 文档
- Boost ASIO:文档不完整