久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用身份驗(yàn)證 cookie 打開(kāi) WebSocket 連接

Open WebSocket connection with authentication cookie(使用身份驗(yàn)證 cookie 打開(kāi) WebSocket 連接)
本文介紹了使用身份驗(yàn)證 cookie 打開(kāi) WebSocket 連接的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

我遇到了與 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 webSocketOrderClient = new WebSocketOrderClient(uri, new Draft_17(), cmap, TIMEOUT);
SSLContext sslContext = null;
sslContext = SSLContext.getInstance( "TLS" );
sslContext.init( null, null, null ); // will use java's default key and trust store which is sufficient unless you deal with self-signed certificates

webSocketOrderClient.setWebSocketFactory(new DefaultSSLWebSocketClientFactory(sslContext));
webSocketOrderClient.connectBlocking();

使用 WebSocketOrderClient:

with WebSocketOrderClient:

private class WebSocketOrderClient extends WebSocketClient {
    public WebSocketOrderClient( URI serverUri, Draft draft, Map<String, String> headers, int timeout) {
        super( serverUri, draft, headers, timeout );
    }
    @Override
    public void onOpen( ServerHandshake handshakedata ) {
        Log.w("connected", "true");
    }
    @Override
    public void onMessage( String message ) {
        Log.w( "got: ", message );
    }
    @Override
    public void onClose( int code, String reason, boolean remote ) {
        Log.w( "Disconnected", ""+code  );
    }
    @Override
    public void onError( Exception ex ) {
        ex.printStackTrace();
    }
}

希望這對(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)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時(shí)間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉(zhuǎn)換為公歷?)
Java: What/where are the maximum and minimum values of a GregorianCalendar?(Java:GregorianCalendar 的最大值和最小值是什么/在哪里?)
Calendar to Date conversion for dates before 15 Oct 1582. Gregorian to Julian calendar switch(1582 年 10 月 15 日之前日期的日歷到日期轉(zhuǎn)換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當(dāng)前星期幾的值)
主站蜘蛛池模板: 男女av| 欧美日韩一区二区三区四区 | 天天综合永久入口 | 成人在线视频免费观看 | 欧美一区免费 | 日韩在线免费观看视频 | 97久久精品午夜一区二区 | 久久久久久成人 | 91久色| 日韩在线观看网站 | 国产在线播 | 九九热这里 | 欧美日韩在线观看视频网站 | 亚洲免费网| 午夜精品久久久久久 | 免费中文字幕 | 国内成人免费视频 | 久久综合888| 特黄特色大片免费视频观看 | 亚洲精品99999 | 日韩欧美视频免费在线观看 | 国产成人自拍一区 | 啪啪毛片 | 亚洲深夜福利 | 久久蜜桃av一区二区天堂 | 一级黄色片在线免费观看 | 精品中文字幕一区二区三区 | 亚洲在线一区二区 | 中文字幕高清 | 91色在线| 九九精品在线 | 久久99精品久久久久久 | 亚洲精品一 | 成人激情视频 | 手机看黄av免费网址 | 天天综合永久 | 国产一区亚洲 | 成人精品鲁一区一区二区 | 午夜综合 | 国产精品免费一区二区三区四区 | 欧美激情 一区 |