使用NodeJS或其他手段欺骗/检测浏览器请求

问题描述

  • 我的网站向第三方公共api发出http发布请求。他们可以完美地工作。
  • 如果我通过NodeJS脚本在本地发出相同的请求,则根据我发送的标头,将收到403或500错误。

问题:

  • 服务器能否可靠地检测到请求是否来自浏览器?
  • 服务器如何检测到它?
  • 是否可以通过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();

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...