hasan
hasan

Reputation: 29

Send browser, referer and cookie with Node.js http GET request

I need to connect to a website.

I use http api from Node.js. I tried to connect directly and I did it. I connected with my default information.

But I want to define my referer and browser information, also my cookies. How can I do that?

Upvotes: 1

Views: 7241

Answers (1)

Adam
Adam

Reputation: 130

You need to define the headers in the options variable.

var http = require('http');

var options = {
    hostname: 'www.google.com',
    path: '/upload',
    headers: {
        'User-Agent': 'whatever',
        'Referer': 'http://localhost/',
        'Cookie': 'COOKIE_NAME=value; COOKIE_NAME=value'
    }
};

http.get(options, callback);

Upvotes: 4

Related Questions