如何使用NodeJS伪造浏览器POST请求?

时间:2017-09-15 14:40:34

标签: javascript node.js http post

我想像浏览器一样向example.com发送POST请求。您提交的example.com上有一个表单,它会为您提供所选子集的信息。

当我使用浏览器提交时,它会显示信息。以下是Chrome中的页眉: Chrome headers

但是,当我尝试从myserver.com发送请求时,我会这样:

request.post({
    url: 'http://example.com',
    json : false,
    withCredentials: true,
    headers: {
        //'POST /study/?id=11 HTTP/1.1':'',
        'Host':'example.com',
        'Connection':'keep-alive',
        'Content-Length':'34',
        'Cache-Control':'max-age=0',
        'Origin':'http://example.com',
        'Upgrade-Insecure-Requests':'1',
        'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36',
        'Content-Type':'application/x-www-form-urlencoded',
        'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
        'Referer':'http://example.com',
        //'Accept-Encoding':'gzip, deflate',
        'Accept-Language':'en-US,en;q=0.8,ru;q=0.6',
        'Cookie':'ssd_num=1m99jeo61eb4srduha9osqr9p2',
        'X-Compress':'null',
    },
    formData: {
        'tmtblTip':'0',
        'showKla':'10%E0',
        'sbShRKl':'1'
    },
    encoding: null
}, (err, res, data) => {
    if (err) {
        console.log('Error:', err);
    } else if (res.statusCode !== 200) {
        console.log('Status:', res.statusCode);
    } else {
        // data is already parsed as JSON:
        //let bodyWithCorrectEncoding = iconv.decode(data, 'win1251');
        let bodyWithCorrectEncoding = toUtf(data, 'utf8','win1251');
        console.log(bodyWithCorrectEncoding);
    }
});

当我执行此操作时,它会返回网页,但会显示There's no such subset

请告诉我这些请求(我的和浏览器)有什么区别?

0 个答案:

没有答案