开发者工具控制台报这个问题怎么解决?
发布于 5 年前 作者 guiying50 10920 次浏览 来自 问答

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)

        })        

      },

      

    })

  })

  },

回到顶部