2

Im working with NODE.js Im using 'request' module :

It works:

var request = require('request');
request('http://www.site.com', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body);
  }
});

When I try to include parameters it crashs!

var request = require('request');
request('http://www.site.com/index.php?action=y9sadf98yh', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body);
  }
});

Error: undefined is not a valid uri or options object.
    at request (/node_modules/request/index.js:1217:41)
    at Request._callback (nodeCloseSession/index.js:60:5)
    at Request.self.callback (/node_modules/request/index.js:148:22)
    at Request.EventEmitter.emit (events.js:98:17)
    at Request.<anonymous> (/node_modules/request/index.js:876:14)
    at Request.EventEmitter.emit (events.js:117:20)
    at IncomingMessage.<anonymous> (/node_modules/request/index.js:827:12)
    at IncomingMessage.EventEmitter.emit (events.js:117:20)
    at _stream_readable.js:883:14
    at process._tickCallback (node.js:415:13)

How to use parameters in NODE.js 'request' module?

2
  • Can you post the crash traceback? Commented May 24, 2013 at 20:05
  • I think you have a bug in your real code but when you tried to simplify it to post here, you avoided it. Whatever you are passing to request() in your real code is undefined. The example posted works fine for me. Commented May 24, 2013 at 20:12

2 Answers 2

3

You can try and use Requestify as alternative, a small and very simple HTTP client for nodeJS + it supports caching..

To perform your request do the following:

var requestify = require('requestify');

requestify.get('http://www.site.com/index.php?action=y9sadf98yh')
  .then(function(response) {
      // Get the response body (JSON parsed or jQuery object for XMLs)
      response.getBody();
  }
);

OR:

var requestify = require('requestify');

requestify.get('http://www.site.com/index.php', { 
    params: {
      action: 'y9sadf98yh'
    }
})
  .then(function(response) {
      // Get the response body (JSON parsed or jQuery object for XMLs)
      response.getBody();
  }
);
Sign up to request clarification or add additional context in comments.

Comments

0
request('/www.site.com/', function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body);
  }
});

use userAgent to get your parameter vaule

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.