keenwon
keenwon

Reputation: 99

the http.request return a wrong statusCode?

I use this code:

var options = {
    hostname: 'torcache.net',
    path: '/torrent/4C1E01E1E7AE19082F4BAC9C3C82B5B2CD0EEA23.torrent',
    port: 80,
    method: 'GET'
};

http.request(options, function (res) {

    var chunks = [];
    res.on('data', function (chunk) {
        chunks.push(chunk);
    });

    res.on('end', function () {
        if (res.statusCode !== 200) {
            callback(res.statusCode);
            return;
        }

        //...
    });
}).on('error', function (err) {
    callback(err);
}).end();

the statusCode is 200, but open the url(http://torcache.net/torrent/4C1E01E1E7AE19082F4BAC9C3C82B5B2CD0EEA23.torrent) is Chrome, the statusCode is 404. what's wrong with the code?

update:
I find if I use this options:

{
    hostname: 'torcache.net',
    path: '/torrent/4C1E01E1E7AE19082F4BAC9C3C82B5B2CD0EEA23.torrent',
    port: 80,
    method: 'GET',
    secureProtocol: 'SSLv3_method',
    headers: {
        'accept-charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
        'accept-language': 'en-US,en;q=0.8',
        'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13+ (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2',
        'accept-encoding': 'gzip,deflate',
        'referer': 'http://torcache.net'  // !!!
    }
}

when the headers['referer'] is not null, the res.statusCode is wrong. but I don't know why?

Upvotes: 0

Views: 180

Answers (1)

Madara's Ghost
Madara's Ghost

Reputation: 174957

The request does indeed return with a 200. It is later redirect with JavaScript to a 404 page, which Node doesn't follow.

Upvotes: 1

Related Questions