收藏
回答

Websocket服务调用失败仍然调用success回调方法?

通过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.





回答关注问题邀请回答
收藏

1 个回答

  • 社区技术运营专员--许涛
    社区技术运营专员--许涛
    2022-06-09

    你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)

    2022-06-09
    有用
    回复
登录 后发表内容