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

使用身份驗證 cookie 打開 WebSocket 連接

Open WebSocket connection with authentication cookie(使用身份驗證 cookie 打開 WebSocket 連接)
本文介紹了使用身份驗證 cookie 打開 WebSocket 連接的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我遇到了與 Android 中的 Websockets 和 cookie 相同的問題,并且我有一直在嘗試按照第一條評論的建議解決它,

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.但盡管如此,我無法打開 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.

我有一個 Apache http cookie,并且需要這個來通過 WebSocket 向服務器驗證我自己的身份.將 cookie 轉換為 httpHeader 的正確方法是什么,或者有什么巧妙的方法可以在連接到 websocket 時簡單地將整個 cookie 添加到身份驗證中?也許我只是錯過了明顯的..

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..

對可能的術語誤用表示歉意,但我希望您能大致了解.

Apologies for possible misuses of terms, but I hope you get the general idea.

任何幫助將不勝感激,謝謝!

Any help would be much appreciated, thank you!

推薦答案

所以我實際上設法解決了它,結果發現實際問題不是cookie,而是websocket沒有初始化一個有效的 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();
    }
}

希望這對將來可能遇到此問題的任何人有所幫助.

Hope this helps anyone who might run into this problem in the future.

這篇關于使用身份驗證 cookie 打開 WebSocket 連接的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Parsing an ISO 8601 string local date-time as if in UTC(解析 ISO 8601 字符串本地日期時間,就像在 UTC 中一樣)
How to convert Gregorian string to Gregorian Calendar?(如何將公歷字符串轉換為公歷?)
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 日之前日期的日歷到日期轉換.公歷到儒略歷切換)
java Calendar setFirstDayOfWeek not working(java日歷setFirstDayOfWeek不起作用)
Java: getting current Day of the Week value(Java:獲取當前星期幾的值)
主站蜘蛛池模板: 久久99精品久久久久久国产越南 | 亚洲精品视频在线 | 日韩中文字幕在线视频 | 日韩精品一区二区三区中文字幕 | 国产99久久久国产精品 | 综合色播| 日本电影免费完整观看 | 国产日韩一区二区 | 亚洲一区二区三区视频免费观看 | 一区二区在线 | 精品国产一区二区三区日日嗨 | 伊人网伊人网 | 国产99久久精品一区二区永久免费 | 亚洲日本成人 | 极品在线| 国产一区在线免费观看视频 | 国产乱码精品一区二区三区中文 | 免费国产视频在线观看 | 欧洲尺码日本国产精品 | 激情久久网 | 99久久成人 | 亚洲国产精品成人无久久精品 | 麻豆国产一区二区三区四区 | 国内精品久久影院 | 日韩电影中文字幕 | 国产精品1区 | 欧美成人性生活 | 网站国产 | 日韩国产免费观看 | 97精品国产手机 | 黄色一级大片在线观看 | 欧美精三区欧美精三区 | 亚洲美女在线一区 | 成人免费观看男女羞羞视频 | 国产成人小视频 | 91国自视频| 精品久久久一区 | 亚洲第1页 | 久久国产电影 | 国产午夜精品久久久 | 日韩一区二区在线视频 |