java - Open WebSocket connection with authentication cookie -
i have same issue websockets , cookies in android, , have been trying solve first comment suggested,
websocketclient( uri serveruri , draft protocoldraft , map httpheaders , int connecttimeout)
using java-websocket, looking @ many other apis such jetty , androidasync. despite unable open websocket connection.
i have apache http cookie, , need authenticate myself server websocket. correct way of translating cookie httpheader, or there neat way add entire cookie in authentication when connection websocket? maybe missing obvious..
apologies possible misuses of terms, hope general idea.
any appreciated, thank you!
so managed solve it, , turned out not cookie actual issue, rather websocket not initialized valid sslcontext. solved rather by:
websocketorderclient websocketorderclient = new websocketorderclient(uri, new draft_17(), cmap, timeout); sslcontext sslcontext = null; sslcontext = sslcontext.getinstance( "tls" ); sslcontext.init( null, null, null ); // use java's default key , trust store sufficient unless deal self-signed certificates websocketorderclient.setwebsocketfactory(new defaultsslwebsocketclientfactory(sslcontext)); websocketorderclient.connectblocking();
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 helps might run problem in future.
Comments
Post a Comment