c++ - nghttp2-asio:在 header 中设置内容类型的正确方法

标签 c++ nghttp2

我想出了这段代码,但不确定是否正确的用法:

    boost::system::error_code ec;

    nghttp2::asio_http2::header_map headers;
    headers.insert(std::pair<std::string, nghttp2::asio_http2::header_value>("content-type", {"application/json; charset=utf-8", false}));
    headers.insert(std::pair<std::string, nghttp2::asio_http2::header_value>("content-length",{std::to_string(r.length()), false}));

    auto req = session->submit(ec, "POST", uri, r.data(), headers);
谁能告诉我这是否正确用法。
谢谢

最佳答案

是的,您所做的是在nghttp2 asio中设置 header 的正确方法。请阅读文档以了解sensitive字段here的用法。
为简便起见,您可以使用std::make_pair。例如:headers.insert(std::make_pair("content-type", {"application/json; charset=utf-8", false}));

关于c++ - nghttp2-asio:在 header 中设置内容类型的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64411846/

相关文章:

c++ - 如何在opengl中停止拉伸(stretch)

c++ - 在 Cmake 中使用 Cuda 对象链接

c++ - 0's coming out as -85993460 instead of 0' 的数组

c++ - 头文件中的拆分命名空间

Jetty HTTP/2 客户端接收服务器推送示例

apache2.4 - 当我进行http2推送时,我向服务器发出请求?

c++ - pthread Windows 事件等效问题

c++ - TLS : no application protocol negotiated

php - HTTP2 和继续执行 PHP

http2 - nghttp2 多部分 POST 消息