繁体   English   中英

从Lambda函数节点js中的api获取响应时获取错误

[英]Gettting error while fetching response from api in lambda function node js

当我打算使用AMAZON ALEXA时,我的lambda函数没有收到来自api的回复...

并获得响应-对不起,发生错误。 请再说一遍。

函数httpsGet(myData,callback){

var options = {
    host: 'cp6gckjt97.execute-api.us-east-1.amazonaws.com',
    port: 80,
    path: '/prod/stateresource?usstate=' + encodeURIComponent(myData),
    method: 'GET',
};



var req = https.request(options, res => {
    res.setEncoding('utf8');
    var returnData = "";
    res.on('data', chunk => {
        returnData = returnData + chunk;
    });
    res.on('end', () => {
        console.log(JSON.stringify(returnData))
        var pop = JSON.parse(returnData).population;
        callback(pop);  // this will execute whatever function the caller defined, with one argument

    });
});
req.end();

}

const GetProductList_Handler =  {
  canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest' && request.intent.name === 'GetProductList' ;

},

async handle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
const responseBuilder = handlerInput.responseBuilder;
let sessionAttributes = handlerInput.attributesManager.getSessionAttributes();

var myRequest = 'Florida';
httpsGet(myRequest,  (myResult) => {
    say = "there2"+JSON.stringify(myResult);
});

    return responseBuilder
        .speak(say)
        .reprompt('try again, ' + say)
        .getResponse();
},

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM