html52.com
我爱小程序-开发者交流社区

开发者工具控制台报这个问题怎么解决?

WebSocket connection to 'ws://127.0.0.1:8080/sub/websocket' failed: Error during WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no response was received

js代码:

/**

   * 生命周期函数--监听页面显示

   */

  onShow: function () {

    var that = this

    wx.connectSocket({

      url: 'ws://172.0.0.1:8080/sub/websocket',

      header:{

        'content-type': 'application/json'

      },

      protocols: ['protocol1']

    })


   wx.onSocketOpen(function (res){

    wx.sendSocketMessage({

      data: "hello world",

      success(){

        wx.onSocketMessage(function(re){

          that.setData({ response: re.data})

          console.log("SocketMessage: "+re.data)

        })        

      },

      

    })

  })

  },


网友回复

社区技术运营专员-Jahozheng:

可以试试使用最新的 rc 版本https://developers.weixin.qq.com/miniprogram/dev/devtools/rc.html

https://developers.weixin.qq.com/miniprogram/dev/devtools/rc.html


评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付