简体   繁体   English

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

[英]what is the user agent string (github api)

So, I'm attempting to make an HTTP request to github to return a list of all the issues on a particular github repository. 因此,我正在尝试向github发出HTTP请求,以返回特定github存储库上所有问题的列表。 I'm using coffeescript in my code below but it should be fairly self explanatory for any JS developer. 我在下面的代码中使用coffeescript,但是对于任何JS开发人员来说,它应该都是很容易解释的。 my confusion is that if I enter " https://api.github.com/repos/username/repo-name/issues " into my browser I can retrieve all of the info that I'm looking for. 我的困惑是,如果我在浏览器中输入“ https://api.github.com/repos/username/repo-name/issues ”,我可以检索到我正在寻找的所有信息。 I get an error saying "Missing or invalid User Agent string" when I try to make the request through my application with the request node library . 当我尝试通过带有请求节点库的应用程序发出请求时,出现错误消息“缺少或无效的用户代理字符串”。 Please let me know if you know how to properly structure a URL to actually retrieve information from the github API. 如果您知道如何正确构造URL以便从github API实际检索信息,请告诉我。

githubUrl = "https://api.github.com/repos/#{username}/#{repoName}/issues?state=open"

    request githubUrl, (error, response, body) ->

        console.log body

You need to pass a user agent string like it says :) I just pulled one from chrome: 您需要传递一个用户代理字符串,就像它说的那样:)我只是从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+'');
    });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM