【发布时间】:2018-04-20 23:16:04
【问题描述】:
我正在学习 Alexa Skill 工具包并制作一个简单的技能来实现 Alexa 设备地址 api。但是,当我在 AWS 平台上测试代码时,它返回“null”作为响应,并且在我得到的日志中:
{ Error: connect ECONNREFUSED 127.0.0.1:443
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 443 }
(不是日志中的所有信息,但我认为这是导致问题的部分)
这是我的代码:
function locationIntent(context,callback) {
var cardTitle = 'Location';
var deviceId = context.context.System.device.deviceId;
var accessToken = context.context.System.apiAccessToken;
var endpoint = context.context.System.apiEndpoint;
var url = endpoint+"/v1/devices/"+deviceId+"/settings/address";
var options = {
Host: "api.amazonalexa.com",
Endpoint:"/v1/devices/"+deviceId+"/settings/address",
Authorization: "Bearer" +accessToken
};
getLocation(options,function(rep,err){
if(err){
console.log(err);
}else{
var speechOutput = "Your adress is "+rep.addressLine1;
var repromptText = speechOutput;
var shouldEndSession = true;
callback({},
buildSpeechletResponse(cardTitle, speechOutput, repromptText, shouldEndSession));
}});
}
function getLocation(options,callback){
https.get(options,function(res){
var body = '';
res.on('data',function(chunk){
body+=chunk;
});
res.on('end',function(){
var result = JSON.parse(body);
console.log(result);
try{
callback(result);
}catch(e){
console.log("error\n"+e);
callback("Something is wrong");
}
});
}).on('error',function(e){
console.log("error in api:"+e);
callback('',e);
});
}
所以我真的很想知道我的代码有什么问题。谢谢大家:)
【问题讨论】:
-
只是猜测,但由于端口是 443,请尝试使用
https.get而不是http。 -
试过但没有任何改变,但还是谢谢。
标签: node.js api https alexa alexa-skills-kit