使用节点 js 向 WhatsApp 打开 wss 时获取 403
Posted
技术标签:
【中文标题】使用节点 js 向 WhatsApp 打开 wss 时获取 403【英文标题】:Get 403 while opening wss with node js to WhatsApp 【发布时间】: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
【问题讨论】:
【参考方案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);
【讨论】:
以上是关于使用节点 js 向 WhatsApp 打开 wss 时获取 403的主要内容,如果未能解决你的问题,请参考以下文章
如何在不打开 WhatsApp 的情况下向 WhatsApp 群组发送消息?