-
-
Save khadorkin/2408b47f350e75241eda to your computer and use it in GitHub Desktop.
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
module.exports = function urlFetch(urlString, callback) { | |
var url = require('url').parse(urlString); | |
var module = url.protocol === 'https:' ? require('https') : require('http'); | |
require('http').get({ | |
host: url.hostname, | |
port: url.port, | |
path: url.path | |
}, function(res) { | |
var body = ''; | |
res.on('data', function(chunk) { | |
body += chunk; | |
}); | |
res.on('end', function() { | |
if (res.statusCode === 200) { | |
callback(null, body); | |
} else { | |
console.error('HTTP POST to ' + urlString + ' faled ' + res.statusCode); | |
} | |
}); | |
}).on('error', function(e) { | |
console.log('errror'); | |
console.log(e); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment