我想出了这段代码,但不确定是否正确的用法:
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/