问题:同样的js websocket wss代码,在Android上可以,在iPhone上报错(iPhone是2021升级系统后,不行的)
onerror回调方法:{"isTrusted":true}
onclose回调方法:1006
代码:
function createWebSocket() {
if(!window.WebSocket) {
console.error("browser not support websocket");
mui.toast("当前手机不支持websocket,无法进行实时监控,请升级手机系统");
return;
}
var url = "wss://www.test.com:8443/monitor?token=123456";
console.log("create websocket " + url);
// 初始化,并连接
var ws = new WebSocket(url);// html5 api
ws.onopen = function() {
};
ws.onmessage = function(evt) {
};
ws.onerror = function(evnt) {
};
ws.onclose = function(evnt) {
};
}
解决:
1. 刚开始,怀疑是跨域,在网上也找了一些资料,在Tomcat web.xml中,添加支持跨域配置后,不行;
2. apple UIWebView =》WKWebview,在HBuilder中,使用新的WKWebView,也不行;
https://ask.dcloud.net.cn/question/89737
3. 后来发现服务端,SSL证书过期,替换新的证书,解决问题;
TODO iPhone抓包 https ,或在Mac 释放热点上抓包
android iphone 上实现区别
参考:
https://blog.csdn.net/weixin_39364136/article/details/83585569 怎样比较HTML5 websocket api options
https://html.spec.whatwg.org/multipage/web-sockets.html
https://ask.dcloud.net.cn/article/12565
https://developer.mozilla.org/zh-CN/docs/Web/Guide/HTML/HTML5
https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API
https://developer.mozilla.org/zh-CN/docs/Web/API/WebSockets_API