使用最後一次Android-Webview更新(52.0.2743.98),我非常難以使用Cordova將cookies發送到我的websocket服務器。在Android上使用Cordova Websockets發送cookie
我使用的身份驗證cookie和驗證碼用於更新之前很好地工作: this.websocket = new WebSocket(url);
我甚至嘗試另一種方式握手過程中強制餅乾頭,但它不工作:
this.websocket = new WebSocket(
url,
[],
{ headers: { Cookie: 'key=value' } }
);
這裏是服務器響應:
WebSocket connection to 'wss://api.my.url/dev/ws' failed:
Error during WebSocket handshake: Unexpected response code: 403
而根據網絡選項卡中鉻:
Request:
Accept-Encoding:gzip, deflate
Accept-Language:en-GB,en-US;q=0.8
Cache-Control:no-cache
Connection:Upgrade
Host:api.host.com
Origin:file://
Pragma:no-cache
Sec-WebSocket-Extensions:permessage-deflate; client_max_window_bits
Sec-WebSocket-Key:<random value>==
Sec-WebSocket-Version:13
Upgrade:websocket
User-Agent:Mozilla/5.0 (Linux; Android 6.0.1; Nexus 6P Build/MTC19X; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/52.0.2743.98 Mobile Safari/537.36
X-Requested-With:com.domain
Response:
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type
Access-Control-Allow-Methods:GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Origin:file://
Connection:keep-alive
Content-Encoding:gzip
Content-Type:application/json; charset=utf-8
Date:Thu, 11 Aug 2016 13:47:09 GMT
Server:nginx/1.8.1
Set-Cookie:key=<random id>; Path=/
Transfer-Encoding:chunked
Vary:Accept-Encoding
注意,它仍然適用於Chrome和iOS(和Android的web視圖的以前的版本)
任何建議?
不認爲我們可以通過協議明確地傳遞websocket上的頭文件。然而默認cookie應該已經通過每個請求正常http或ws。我也在android的更新版本上面臨同樣的問題。 – Ashish
您是否找到了解決方案? –