【问题标题】:nghttp2-asio : Proper way to set content-type in headernghttp2-asio :在标头中设置内容类型的正确方法
【发布时间】:2021-02-01 07:33:42
【问题描述】:

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

    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);

谁能告诉我这是否正确使用。

谢谢

【问题讨论】:

    标签: c++ nghttp2


    【解决方案1】:

    是的,您所做的是在nghttp2 asio 中设置标题的正确方法。请阅读文档以了解sensitive 字段here 的用法。

    为简洁起见,您可以使用std::make_pair。例如:

    headers.insert(std::make_pair("content-type", {"application/json; charset=utf-8", false}));

    【讨论】:

      猜你喜欢
      • 2019-03-28
      • 2012-12-30
      • 1970-01-01
      • 2014-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多