收藏
回答

小程序服务和websocket使用域名访问,websocket无法连接但code

小程序服务和websocket使用域名访问,websocket无法连接但code200


 appservice?t=1560474138273:1305 WebSocket connection to 'wss://xxx.com/ failed: Error during WebSocket handshake: Unexpected response code: 200 


最后一次编辑于  2019-06-14
回答关注问题邀请回答
收藏

1 个回答

  • 是小白啊
    是小白啊
    2019-06-14

    麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)

    2019-06-14
    有用
    回复 2
    • JumoSmile
      JumoSmile
      2019-06-14

      还在微信开发者工具上测试

      服务端

      const Koa = require('koa');

      var app = new Koa();

      const fs = require('fs');

      const http = require('http');

      const https = require('https');


      const server = http.createServer(app.callback());

      var WebSocket = require('ws');

      var WebSocketServer = WebSocket.Server;

      wss = new WebSocketServer({server,verifyClient: ClientVerify});


      const httpsOption = {

      key:  fs.readFileSync("./https/xxx.key"),

      cert: fs.readFileSync("./https/xxx.pem")

      };

      server.listen(80);

      https.createServer(httpsOption,app.callback()).listen(443);


      客户端

       webSocketTask = wx.connectSocket({
              url: 'wss://xxx.com/?id=luoc83&key=KiddLo09',
              header: {
                'content-type': 'application/json'
              },
              method: 'POST',
              success: function (res) {
                wx.hideLoading();
              },
              fail: function (err) {
                wx.hideLoading();
                wx.showToast({


      2019-06-14
      回复
    • 是小白啊
      是小白啊
      2019-06-14回复JumoSmile

      代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)这个格式的代码片段

      2019-06-14
      回复
登录 后发表内容