3

以下のコードを使用して、gitHubからリポジトリを取得しています。ホームネットワークから使用すると、リポジトリのリストを取得できますが、他のネットワークからリポジトリを取得しようとすると、「connectECONNREFUSED」というエラーが発生します。私は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();
4

2 に答える 2

3

これでいいと思います

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)'}

};
于 2014-05-10T11:01:42.800 に答える
3

オプションを次のように変更します

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)'}

};
于 2014-02-14T08:55:54.727 に答える