什么是用户代理字符串(github api)

what is the user agent string (github api)

本文关键字:github api 字符串 用户代理 什么      更新时间:2023-09-26

因此,我试图向github发出HTTP请求,以返回特定github存储库上所有问题的列表。我在下面的代码中使用coffeescript,但对于任何JS开发人员来说,它应该是相当不言自明的。我的困惑是,如果我在浏览器中输入"https://api.github.com/repos/username/repo-name/issues",我可以检索我正在寻找的所有信息。当我试图通过带有请求节点库的应用程序发出请求时,我得到一个错误,说"丢失或无效的用户代理字符串"。请让我知道,如果你知道如何正确地构建一个URL,以实际从github API检索信息。

githubUrl = "https://api.github.com/repos/#{username}/#{repoName}/issues?state=open"
    request githubUrl, (error, response, body) ->
        console.log body

你需要传递一个用户代理字符串,就像它说:)我刚刚从chrome:

require( 'https' )
    .get({
         hostname : 'api.github.com'
        ,    path :'/repos/cwolves/jquery-imask/issues'
        , headers : {
            'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1521.3 Safari/537.36'
        }
    }, function(res){
        res.on('data',function(data){
            console.log(data+'');
    });
});