首页 > 解决方案 > 使用 NodeJS 或其他方式欺骗/检测浏览器请求

问题描述

问题:

// This is what I tried.
// Headers are copied from my website's actual requests via Chrome Dev Tool's network tab.
const https = require('https')

const options = {
    host: 'api.com',
    port: 443,
    path: '/form',
    method: 'POST',
    headers: {
        Accept: '*/*',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'en-GB,en-US;q=0.9,en;q=0.8,de;q=0.7',
        Connection: 'keep-alive',
        'Content-Length': '127',
        'Content-Type': 'application/x-www-form-urlencoded',
        Host: 'api.com',
        Origin: 'https://www.mywebsite.com',
        Referer: 'https://www.mywebsite.com/',
        'Sec-Fetch-Dest': 'empty',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Site': 'same-site',
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36',
    },
    form: {
        name: 'My Name'
    }
};

const req = https.request(options, function (res) {
    console.log('STATUS: ' + res.statusCode);
    console.log('HEADERS: ' + JSON.stringify(res.headers));
    res.setEncoding('utf8');
    res.on('data', function (chunk) {
        console.log('BODY: ' + chunk);
    });
})

req.end();

标签: node.jshttpsecuritybrowserspoofing

解决方案


推荐阅读