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)
})
},
})
})
},
可以试试使用最新的 rc 版本https://developers.weixin.qq.com/miniprogram/dev/devtools/rc.html
把protocols修改为[]即可