Setting user-agent with node js
The group you are posting to is a
Usenet group . Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
From:
santa <santosh.srini... @gmail.com>
Date: Fri, 20 Jul 2012 23:42:28 -0700 (PDT)
Local: Sat, Jul 21 2012 2:42 am
Subject: Setting user-agent with node js
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
mscdex <msc... @gmail.com>
Date: Sat, 21 Jul 2012 03:56:38 -0700 (PDT)
Local: Sat, Jul 21 2012 6:56 am
Subject: Re: Setting user-agent with node js
On Saturday, July 21, 2012 2:42:28 AM UTC-4, santa wrote:
> I am trying to use superagent to request data from a server. I believe the > problem is setting the 'user-agent' in the request but I am having a tough > time figuring out the problem. I get an access denied error.
Did you try using the core HTTP methods?
Example (untested):
var http = require('http');
http.get({ host: 'www.nseindia.com' ,<http://www.nseindia.com/live_market/dynaContent/live_watch/stock_watc... > path: ' /live_market/dynaContent/live_watch/stock_watch/juniorNiftyStockWatch.json<http://www.nseindia.com/live_market/dynaContent/live_watch/stock_watc... > ', headers: { 'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13' }
}, function(res) {
if (res.statusCode === 200) {
var body = [];
res.setEncoding('utf8');
res.on('data', function(chunk) {
body.push(chunk);
});
res.on('end', function() {
body = body.join('');
console.log(body);
});
} else {
console.log('Received non-ok response: ' + res.statusCode);
}
});
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
mscdex <msc... @gmail.com>
Date: Sat, 21 Jul 2012 03:58:06 -0700 (PDT)
Local: Sat, Jul 21 2012 6:58 am
Subject: Re: Setting user-agent with node js
On Saturday, July 21, 2012 6:56:38 AM UTC-4, mscdex wrote:
> Did you try using the core HTTP methods?
Additionally, did you try comparing the exact headers sent by cURL and
those sent by superagent (using Wireshark or something else)?
You must
Sign in before you can post messages.
You do not have the permission required to post.
From:
santa <santosh.srini... @gmail.com>
Date: Sat, 21 Jul 2012 04:04:16 -0700 (PDT)
Local: Sat, Jul 21 2012 7:04 am
Subject: Re: Setting user-agent with node js
Tested it. Doesnt work. Same problem. Not sure how to go about it.
On Saturday, July 21, 2012 4:26:38 PM UTC+5:30, mscdex wrote:
> On Saturday, July 21, 2012 2:42:28 AM UTC-4, santa wrote:
>> I am trying to use superagent to request data from a server. I believe >> the problem is setting the 'user-agent' in the request but I am having a >> tough time figuring out the problem. I get an access denied error.
> Did you try using the core HTTP methods?
> Example (untested):
> var http = require('http');
> http.get({ > host: 'www.nseindia.com' ,<http://www.nseindia.com/live_market/dynaContent/live_watch/stock_watc... > > path: ' > /live_market/dynaContent/live_watch/stock_watch/juniorNiftyStockWatch.json<http://www.nseindia.com/live_market/dynaContent/live_watch/stock_watc... > > ', > headers: { > 'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; > rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13' > } > }, function(res) { > if (res.statusCode === 200) { > var body = []; > res.setEncoding('utf8'); > res.on('data', function(chunk) { > body.push(chunk); > }); > res.on('end', function() { > body = body.join(''); > console.log(body); > }); > } else { > console.log('Received non-ok response: ' + res.statusCode); > } > });
You must
Sign in before you can post messages.
You do not have the permission required to post.