预期HTTP 302但使用NodeJS http客户端获取HTTP 301

时间:2012-01-01 06:39:40

标签: http node.js github

我有这个NodeJS snippnet:

require('http').get({
    secure: true,
    host: 'github.com',
    method: 'GET',
    path: '/downloads/Graylog2/graylog2-web-interface/graylog2-web-interface-0.9.6.tar.gz',
    'headers': {
        Host: 'github.com'
    }}).on('response', function(response) {
    console.log(response.statusCode);
});

假设在https://github.com/downloads/Graylog2/graylog2-web-interface/graylog2-web-interface-0.9.6.tar.gz(样本)上执行简单的GET请求

我面临的问题是HTTP状态,使用NodeJS客户端 301 Moved Permanently 。我预计会发现 302 Found (实际上我得到的是Chrome,cUrl,http://web-sniffer.net,...)。

由于

1 个答案:

答案 0 :(得分:0)

请求没有secure选项。您想要的是使用https模块。

require('https')