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)
})
},
})
})
},