-
-
Save aj07mm/ce6619082d020d3edddf to your computer and use it in GitHub Desktop.
GET nodejs with request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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