华为手机上的微信小程序无法连接WebSocket
发布于 5 年前 作者 uchen 11482 次浏览 来自 问答

使用WebSocket与后端交互。使用ws时正常,使用wss+域名:端口后,模拟器和苹果手机可以成功连接,并正常使用,但是华为手机在调用connect后success但是onSocketOpen一直未执行,隔了一段onSocketError执行,并出现TIMED_OUT提示。域名已经完成备案,并在微信号上登记,登记WebSocket的时候带上了端口号以下是连接代码

    sock = wx.connectSocket({

      url: ‘wss://xxxx.com:9504?group=’ + group,

      header: {

        ‘content-type’: ‘application/json’

      },

      method: “GET”,

      fail: res =>{

        console.log(“failed to connect server:”,res)

        this.onDisconnect()

      },

      success: res => {

        console.log(‘connection succeeded:’,res)

        console.log(‘sock:’,sock)

      }

    })

1 回复

请检查是否符合要求:https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html

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

回到顶部