我尝试写一个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
答案 0 :(得分:0)
你必须加上一个标题
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);