【问题标题】:How can I put a custom header for websocket handshake with boost beast如何使用 boost beast 为 websocket 握手添加自定义标头
【发布时间】:2019-02-17 00:27:48
【问题描述】:

如何在与 boost beast 的 WebSocket 协议中发生的第一次握手中发送自定义标头?

我想在我的初始请求“x-custome-id : xxxxx”中使用自定义标头。

【问题讨论】:

标签: c++ boost websocket request-headers beast


【解决方案1】:

你必须把 custum 头文件放在这样的地方

您可能想在这里和那里更改一些细节

ws_.async_handshake_ex(host, <endpoint>,
            [<somerequestname>](request_type& reqHead) {
                reqHead.insert(http::field::<sometype>,xxxxx);},
            bind(Some handler));

注意:

您将获得这些详细信息,例如 hostendpoint

这就是您想要做的正确 - reqHead.insert(http::field::&lt;sometype&gt;,xxxxx);}http::field::&lt;sometype&gt; 中探索适合您的选项 为此探索enum class field : unsigned short

【讨论】:

  • 感谢您的热心帮助!
【解决方案2】:

我发现候选解决方案为https://github.com/boostorg/beast/issues/70
但是,这会在 boost 1.69 中出现编译器错误。
解决方案https://github.com/boostorg/beast/issues/1470 也解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-26
    • 1970-01-01
    • 2014-08-23
    • 1970-01-01
    • 2019-02-21
    • 1970-01-01
    • 1970-01-01
    • 2021-07-17
    相关资源
    最近更新 更多