[英]How to connect to gitHub api using nodejs from a secure network?
我使用以下代码从gitHub获取存储库。 当我在家庭网络中使用它时,我能够检索存储库列表,但是如果我尝试从其他网络获取存储库,它会给我这个错误:'connect ECONNREFUSED'。 我是nodejs的新手,所以仍然想知道如何解决这个问题。
有任何想法吗?
var https = require("https");
var userName='xyz';
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;
});
response.on('end',function(){
var json = JSON.parse(body);
var repos =[];
json.forEach(function(repo){
repos.push({
name : repo.name,
description : repo.description
});
});
console.log('the repos are '+ JSON.stringify(repos));
});
});
request.on('error', function(e) {
console.error('and the error is '+e);
});
request.end();
将您的选项更改为
var options = {
host:'api.github.com',
path: '/users/' + username+ '/repos',
method: 'GET',
headers: {'user-agent':'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)'}
};
我觉得这样可以
var options = {
host:'api.github.com',
path: '/users/' + username+ '/repos',
method: 'GET',
headers: {'User-Agent':'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)'}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.