Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 什么是用户代理字符串(GithubAPI)_Javascript_Node.js_Api_Github_Coffeescript - Fatal编程技术网

Javascript 什么是用户代理字符串(GithubAPI)

Javascript 什么是用户代理字符串(GithubAPI),javascript,node.js,api,github,coffeescript,Javascript,Node.js,Api,Github,Coffeescript,因此,我试图向github发出HTTP请求,以返回特定github存储库中所有问题的列表。我在下面的代码中使用了coffeescript,但对于任何JS开发人员来说,它都应该是不言自明的。我的困惑是,如果我在浏览器中输入“”,我就可以检索我正在查找的所有信息。当我尝试使用通过应用程序发出请求时,出现一个错误,提示“缺少或无效的用户代理字符串”。如果您知道如何正确构造URL以实际从github API检索信息,请告诉我 githubUrl = "https://api.github.com/rep

因此,我试图向github发出HTTP请求,以返回特定github存储库中所有问题的列表。我在下面的代码中使用了coffeescript,但对于任何JS开发人员来说,它都应该是不言自明的。我的困惑是,如果我在浏览器中输入“”,我就可以检索我正在查找的所有信息。当我尝试使用通过应用程序发出请求时,出现一个错误,提示“缺少或无效的用户代理字符串”。如果您知道如何正确构造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+'');
    });
});

您需要传递一个用户代理字符串,如它所示:)我刚刚从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+'');
    });
});