更新:我的http请求端点发生错误。我没有设置适当的认证选项,以便修复很多错误,可能是这个特定的错误。Node.js Lambda函数“响应无效”亚马逊Alexa
我的问题是类似的一个位置:
但是解决这个问题并没有解决我的问题。因此,我向Hana云中的xsjs服务发起http请求调用。我收到'回复无效'的错误讯息。我看不出为什么。这里是我的功能:
// Create a web request and handle the response.
function httpGet(query, callback) {
console.log("/n QUERY: "+ query);
var host = 'datacloudyd070518trial.hanatrial.ondemand.com';
var path = '/LocationInformation/getLocationInfo.xsjs?location=';
var hostname = 'https://' + host + path + query;
var auth = 'user1:D1anafer';
var req = http.request({'hostname': hostname,
'auth': auth
}, (res) => {
var body = '';
res.on('data', (d) => {
body += JSON.stringify(d);
});
res.on('end', function() {
callback(body);
});
});
req.end();
req.on('error', (e) => {
console.error(e);
});
}
并调用它的功能:
'getNewsIntent': function() {
//self = this;
httpGet(location, function (response) {
// Parse the response into a JSON object ready to be formatted.
//var output = JSON.parse(response);
//output = output['change'];
var output = response;
var cardTitle = location;
var cardContent = output;
alexa.emit(':tellWithCard', output, cardTitle, cardContent);
});
},
谢谢 -Diana