Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Setting user-agent with node js
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
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:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
santa  
View profile  
 More options Jul 21 2012, 2:42 am
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

Hello All,

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.

For example from the shell first:

A)
curl 'http://www.nseindia.com/live_market/dynaContent/live_watch/stock_watc...
This gives access denied

B) curl --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'
'http://www.nseindia.com/live_market/dynaContent/live_watch/stock_watc...
This works!

However when I use SuperAgent it fails. Can someone please help me fix this?
I am using the following code:

    var request = require('superagent');
    request

 .get('http://www.nseindia.com/live_market/dynaContent/live_watch/stock_watc...)
        .set('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')
        .end(function(res){
        if (res.ok) {
         console.log(res.text);
        }
        else {
           console.log(res);
           }
        });

Thanks,
Santosh


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mscdex  
View profile  
 More options Jul 21 2012, 6:56 am
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.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mscdex  
View profile  
 More options Jul 21 2012, 6:58 am
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.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
santa  
View profile  
 More options Jul 21 2012, 7:04 am
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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »