简体   繁体   English

如何使用 boost beast 为 websocket 握手添加自定义标头

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

How to send custom headers in the first handshake that occurs in the WebSocket protocol with boost beast ?如何在带有 boost beast 的 WebSocket 协议中发生的第一次握手中发送自定义标头?

I want to use custom header in my initial request "x-custome-id : xxxxx".我想在我的初始请求“x-custome-id:xxxxx”中使用自定义标头。

You will have to put the custum header somthing like this您将不得不像这样放置 custum 标题

You might want to change a few details here and there您可能想在这里和那里更改一些细节

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

Note:笔记:

you will have theses details like host , endpoint ,etc您将拥有hostendpoint等这些详细信息

This is what you want to get right - reqHead.insert(http::field::<sometype>,xxxxx);} Explore the option suitable for you in http::field::<sometype> explore the enum class field : unsigned short for this.这就是您想要正确的 - reqHead.insert(http::field::<sometype>,xxxxx);}http::field::<sometype>探索适合您的选项探索枚举类字段:无符号对此的简称

I've found the candidate solution as https://github.com/boostorg/beast/issues/70 .我发现候选解决方案为https://github.com/boostorg/beast/issues/70
But, this occurs compiler error with boost 1.69.但是,这会在 boost 1.69 中发生编译器错误。
This issue also fixed with the solution https://github.com/boostorg/beast/issues/1470 .此问题也通过解决方案https://github.com/boostorg/beast/issues/1470解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM