[英]How to connect to gitHub api using nodejs from a secure network?
I am using the below code to get the repositories from gitHub. 我使用以下代码从gitHub获取存储库。 When I use it from Home network I am able to retrieve the list of repositories, but If I try to fetch the repo from other network it gives me this error: 'connect ECONNREFUSED'.
当我在家庭网络中使用它时,我能够检索存储库列表,但是如果我尝试从其他网络获取存储库,它会给我这个错误:'connect ECONNREFUSED'。 I am new to nodejs, so still wondering how to go about solving this issue.
我是nodejs的新手,所以仍然想知道如何解决这个问题。
Any ideas? 有任何想法吗?
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();
Change your options as 将您的选项更改为
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)'}
};
i think this would be OK 我觉得这样可以
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.