問(wèn)題描述
我遇到了與 Android 中的 Websockets 和 cookie 相同的問(wèn)題,并且我有一直在嘗試按照第一條評(píng)論的建議解決它,
I have the same issue as Websockets and cookies in Android, and I have been trying to solve it as the first comment suggested,
WebSocketClient( URI serverUri , Draft protocolDraft , Map httpHeaders , int connectTimeout)
WebSocketClient( URI serverUri , Draft protocolDraft , Map httpHeaders , int connectTimeout)
使用 Java-WebSocket,以及查看許多其他 API,例如 Jetty 和AndroidAsync.但盡管如此,我無(wú)法打開(kāi) websocket 連接.
using Java-WebSocket, as well as looking at many other APIs such as Jetty and AndroidAsync. But despite this I am unable to open up a websocket connection.
我有一個(gè) Apache http cookie,并且需要這個(gè)來(lái)通過(guò) WebSocket 向服務(wù)器驗(yàn)證我自己的身份.將 cookie 轉(zhuǎn)換為 httpHeader 的正確方法是什么,或者有什么巧妙的方法可以在連接到 websocket 時(shí)簡(jiǎn)單地將整個(gè) cookie 添加到身份驗(yàn)證中?也許我只是錯(cuò)過(guò)了明顯的..
I have an Apache http cookie, and need this to authenticate myself to the server with a WebSocket. What is the correct way of translating a cookie into a httpHeader, or is there any neat way to simply add the entire cookie in the authentication when connection to a websocket? Maybe I am just missing the obvious..
對(duì)可能的術(shù)語(yǔ)誤用表示歉意,但我希望您能大致了解.
Apologies for possible misuses of terms, but I hope you get the general idea.
任何幫助將不勝感激,謝謝!
Any help would be much appreciated, thank you!
推薦答案
所以我實(shí)際上設(shè)法解決了它,結(jié)果發(fā)現(xiàn)實(shí)際問(wèn)題不是cookie,而是websocket沒(méi)有初始化一個(gè)有效的 ssl 上下文.這很容易解決:
So I actually managed to solve it, and it turned out that it was not the cookie that was the actual issue, but rather that the websocket is not initialized with a valid sslcontext. This was solved rather easily by:
使用 WebSocketOrderClient:
with WebSocketOrderClient:
希望這對(duì)將來(lái)可能遇到此問(wèn)題的任何人有所幫助.
Hope this helps anyone who might run into this problem in the future.
這篇關(guān)于使用身份驗(yàn)證 cookie 打開(kāi) WebSocket 連接的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!