wx.connectSocket 连接 老是报502 普通浏览器都正常的 奇怪?
发布于 5 年前 作者 gang04 12777 次浏览 来自 问答

WebSocket connection to ‘wss://weilis.xyz/’ failed: Error during WebSocket handshake: Unexpected response code: 502

```

/**

* 生命周期函数--监听页面加载

*/

onLoad: function (options) {

wx.connectSocket({

url: "wss://weilis.xyz"

});

wx.onSocketError(function(err) {

console.log(err);

})

wx.onSocketMessage(function (res) {

console.log('收到服务器内容:' + res)

});

wx.onSocketClose(function (res) {

console.log(res)

});

},

```


证书配置正确,在https://weilis.xyz首页上打开浏览器调试工具在console中输入

```

var s = io("wss://weilis.xyz")

s.connected

true

1 回复

websocket服务端不正确

websocket在线测试

http://www.websocket-test.com/

通过后再编码

回到顶部