Created
February 28, 2015 01:22
-
-
Save gtomitsuka/ca820a0b63379d26085b to your computer and use it in GitHub Desktop.
Request.js
This file contains 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
//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