簡體   English   中英

如何使用 boost beast 為 websocket 握手添加自定義標頭

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

如何在帶有 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
但是,這會在 boost 1.69 中發生編譯器錯誤。
此問題也通過解決方案https://github.com/boostorg/beast/issues/1470解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM