如何用Boost Beast放置一个定制标头,以供Websocket握手

How can I put a custom header for websocket handshake with boost beast

本文关键字:握手 Websocket 以供 一个 Beast Boost 何用      更新时间:2023-10-16

如何在Websocket中使用Boost Beast在WebSocket中的第一个握手发送自定义标头?

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

您将不得不将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::<sometype>,xxxxx);}探索适合您的选项http::field::<sometype>探索枚举类字段:无签名的简称。

我找到了候选解决方案,如https://github.com/boostorg/beast/issues/70。
但是,这发生了编译器误差,升压1.69。
解决方案也解决了此问题https://github.com/boostorg/beast/issues/1470。