Request forbidden while accessing github api on node.js program

前端 未结 1 1908
广开言路
广开言路 2021-02-04 02:46

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

1条回答
  •  野的像风
    2021-02-04 03:05

    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'}
    };
    

    0 讨论(0)
提交回复
热议问题