【问题标题】:Get 403 while opening wss with node js to WhatsApp使用节点 js 向 WhatsApp 打开 wss 时获取 403
【发布时间】:2018-06-06 22:37:07
【问题描述】:

我尝试编写一个 WhatsApp 节点,并想打开一个 wss 连接,但总是得到 403。也许有人看到我的错误:

import WebSocket from 'ws';

const ws = new WebSocket('wss://w8.web.whatsapp.com/ws', '["admin", "init", [0, 2, 7314], ["Mac OS 10.13.2", "Chrome"], true]');

ws.on('open', function open() {
  ws.send('["admin", "init", [0, 2, 7314], ["Mac OS 10.13.2", "Chrome"], true]');
});

ws.on('message', function incoming(data) {
  console.log(data);
});

这只是一个测试,我对值进行了硬编码。

但服务器总是响应 403

【问题讨论】:

    标签: javascript node.js websocket whatsapp http-status-code-403


    【解决方案1】:

    你必须放一个标题

    var WebSocketClient = require('websocket').client;
     
    var client = new WebSocketClient();
     
    client.on('connectFailed', function(error) {
        console.log('Connect Error: ' + error.toString());
    });
     client.onmessage = function(e) {
            console.log(e)
            }
    client.on('connect', function(connection) {
        console.log('WebSocket Client Connected');
    
    
        connection.on('error', function(error) {
            console.log("Connection Error: " + error.toString());
        });
    
        
    
    });
     
    client.connect('wss://w6.web.whatsapp.com/ws', null, null, {
    "Accept-Encoding": "gzip, deflate, br",
    "Accept-Language": "ar,en-US;q=0.9,en;q=0.8", 
    "Cache-Control": "no-cache",
    "Connection": "Upgrade",
    "Host": "w6.web.whatsapp.com",
    "Origin": "https://web.whatsapp.com" ,
    "Pragma": "no-cache",
    "Sec-WebSocket-Extensions": "permessage-deflate; client_max_window_bits",
    'Sec-WebSocket-Key' : 'her ur key from header in url',
    'Sec-WebSocket-Version':"13",
    "Upgrade": "websocket",
    "User-Agent": "here your agent"
    }, null);

    【讨论】:

      猜你喜欢
      • 2020-07-16
      • 2014-05-20
      • 2019-08-13
      • 2023-02-07
      • 1970-01-01
      • 2015-06-30
      • 1970-01-01
      • 1970-01-01
      • 2017-12-07
      相关资源
      最近更新 更多