【问题标题】: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));
注意:
您将获得这些详细信息,例如 host、endpoint 等
这就是您想要做的正确 - reqHead.insert(http::field::<sometype>,xxxxx);} 在http::field::<sometype> 中探索适合您的选项
为此探索enum class field : unsigned short。