使用上一次Android-Webview更新(52.0.2743.98),我很难使用Cordova将cookie发送到我的websocket服务器。
我正在使用Cookie进行身份验证,而且此代码在更新之前用于完美运行:
this.websocket = new WebSocket(url);
我甚至尝试了另一种在握手期间强制cookie标头的方法,但它不起作用:
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
并在Chrome网络标签下:
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-Webview)
任何建议?
答案 0 :(得分:0)
解决问题的更好方法是更改浏览器。现在您使用chrome浏览器显示混合应用程序,您可以更改此默认浏览器。
我遇到了与WebSockets相同的问题,我使用了CrossWalk浏览器,我对WebSockets没有任何问题。您可以在此页面中查看CrossWalk项目:https://crosswalk-project.org/documentation/android.html
我正在使用Ionic来实现我的应用程序,只有我必须运行此命令来安装CrossWalk浏览器:
离子浏览器添加人行横道