Skip to content

Instantly share code, notes, and snippets.

@aj07mm
Created January 16, 2016 03:14
Show Gist options
  • Save aj07mm/ce6619082d020d3edddf to your computer and use it in GitHub Desktop.
Save aj07mm/ce6619082d020d3edddf to your computer and use it in GitHub Desktop.
GET nodejs with request
var request = require('request');
// Set the headers
var headers = {
'User-Agent': 'Super Agent/0.0.1',
'Content-Type': 'application/x-www-form-urlencoded'
}
// Configure the request
var options = {
url: 'https://foo.bar',
method: 'GET',
headers: headers,
//qs: {'key1': 'xxx', 'key2': 'yyy'}
}
// Start the request
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
// Print out the response body
console.log(JSON.parse(body))
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment