通过SocketTask wx.connectSocket(Object object)调用Websocket服务,当服务调用失败时,API仍然调用success回调方法。
let url = "ws://127.0.0.1:7070/ws";
wx.connectSocket({
url: url,
header: {
'content-type': 'text/xml'
},
protocols: ['xmpp'],
success: (message) => {
console.log(`WebSocket connection to ${url} success.${JSON.stringify(message)}`);
},
fail: e => {
throw new Error(`WebSocket connection to ${url} failed. ${e.errMsg}`);
},
complete: res => {
console.log(`WebSocket connection to ${url} complete.`)
}
日志:
WebSocket connection to ws://127.0.0.1:7070/ws success.{"socketTaskId":10,"errMsg":"connectSocket:ok"}
WebSocket connection to ws://127.0.0.1:7070/ws complete.
你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)