我在写一个Alexa技巧,它可以对Google日历进行API调用,但是我的GET请求不起作用。节点GET请求不起作用
var request = require('request');
console.log("Before requests");
// getUrl is the the url and returns the data when entered into my browser
request(getUrl, function (error, response, body) {
console.log('error:', error);
console.log('statusCode:', response && response.statusCode);
console.log('body:', body);
});
我使用request
使HTTP调用这个代码是从字面上刚刚从github page复制,但没有被记录到控制台,所以我不知道如何调试什么错。使用其他方法,如http.get(options, callback)
产生了相同的结果 - 回调中的任何console.log()都不会被执行。有没有人有任何见解?谢谢!
-
一些其他的东西 - 我的console.log("Before requests");
显示出来,而我的getURL可能没有正确的API密钥提出请求,但仍然应该不是返回不工作的错误。
此代码通过Amazon Lambda函数(AWS)运行,并且通过AWS Cloudwatch查看日志。看起来,如果我在我的终端node index.js
中运行我的代码,请求就会很好。
-
console.log(request);
输出:
jar: [Function],
[ 'accept',
'accept-charset',
'accept-encoding',
'accept-language',
'accept-ranges',
'cache-control',
'content-encoding',
'content-language',
'content-location',
'content-md5',
'content-range',
'content-type',
'connection',
'date',
'expect',
'max-forwards',
'pragma',
'referer',
'te',
'user-agent',
'via' ],
defaultProxyHeaderExclusiveList: [ 'proxy-authorization' ] },
initParams: [Function: initParams],
debug: [Getter/Setter]
我之前没有使用'request' - 但是出于好奇,如果'console.log(request)'会发生什么? (在调用它之前,当然) – skwidbreth
可能是传入的url吗? – heyitsjhu
什么是网址? – chenkehxx