Skip to content

Instantly share code, notes, and snippets.

@gtomitsuka
Created February 28, 2015 01:22
Show Gist options
  • Save gtomitsuka/ca820a0b63379d26085b to your computer and use it in GitHub Desktop.
Save gtomitsuka/ca820a0b63379d26085b to your computer and use it in GitHub Desktop.
Request.js
//APIs
var http = require('http');
var url = require('url');
module.exports = function(websiteURL, method) {
return new Promise(function (resolve, decline){
var path = url.parse(websiteURL);
var options = {};
options.hostname = path.hostname;
options.port = path.port;
options.method = method;
var headers = {};
headers.User-Agent = "Montreus-SWC";
options.headers = headers;
var request = http.request(options, function(response){
if(response.statusCode == 200){
var HTML = '';
response.setEncoding('utf8');
response.on('data', function (chunk) {
HTML += chunck.toString();
});
response.on('end', function(){
resolve(HTML);
});
}
});
request.end();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment