I'm trying to run this code but getting this error:
Request forbidden by administrative rules, make sure your request has a User-Agent header
var https = require("https"); var username = 'jquery'; var options = { host: 'api.github.com', path: '/users/' + username + '/repos', method: 'GET' }; var request = https.request(options, function(response){ var body = ''; response.on("data", function(chunk){ body += chunk.toString('utf8'); }); response.on("end", function(){ console.log("Body: ", body); }); }); request.end();
Your options
object does not have the headers
option, describing the user-agent
. Try this:
var options = { host: 'api.github.com', path: '/users/' + username + '/repos', method: 'GET', headers: {'user-agent': 'node.js'} };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With