Nic*_*cky 18 javascript github node.js
我正在尝试运行此代码,但收到此错误:
管理规则禁止请求,请确保您的请求具有User-Agent标头
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();
Run Code Online (Sandbox Code Playgroud)
Rod*_*ros 29
您的options对象没有headers选项,描述了user-agent.试试这个:
var options = {
host: 'api.github.com',
path: '/users/' + username + '/repos',
method: 'GET',
headers: {'user-agent': 'node.js'}
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6011 次 |
| 最近记录: |