NKPDQZ
NKPDQZ
2017-05-03 13:14

关于node.js的https模块的get请求的报错

  • node.js

先贴代码

 var builder = require('botbuilder');
var https = require('https');
var connector = new builder.ConsoleConnector().listen();
var bot = new builder.UniversalBot(connector);
function getBooksData(key){
    https.get("https://www.googleapis.com/books/v1/volumes?q="+key+"&maxResults=5",function(res){

        //console.log("statusCode"+res.statusCode);
        //console.log('headers:', res.headers);
        var d = '';
        var i;
        res.on('data',function(chunk) {
            d += chunk;
        });
        res.on('end',function() {
            var e = JSON.parse(d);
            for (i = 0;i < e.items.length;i++) {
                console.log(i + 1 + ":" + e.items[i].volumeInfo.title);
            }
        });
    });
}

var intents = new builder.IntentDialog();
bot.dialog('/', intents);
intents.matches(/^Hi/i, [
    function(session){
        builder.Prompts.text(session, 'Hey, I am a BookBot. Welcome to Book Searching through Chat!.To start, which books you would like to search?');
    },  
    function(session,results){
        session.send('Here are books for topic - %s.', results.response);
        getBooksData(results.response);
    }
]);
intents.onDefault(builder.DialogAction.send('Hi there! How can I help you today?'));

运行后当请求任意字符从而获取信息的时候,出现了如下错误:
events.js:160
throw er; // Unhandled 'error' event
^

Error: connect ETIMEDOUT 172.217.27.138:443
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect as oncomplete

    应该不是网络的问题(科学上网了)求助这个问题应该怎么破?
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答