我正在尝试运行此代码,但收到此错误:
管理规则禁止请求,请确保您的请求具有用户代理标头
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();
答案 0 :(得分:24)
您的options
对象没有headers
选项,描述了user-agent
。试试这个:
var options = {
host: 'api.github.com',
path: '/users/' + username + '/repos',
method: 'GET',
headers: {'user-agent': 'node.js'}
};