Trello响应“无效的密钥”

我正在尝试使用以下URL使用Node.js的https模块获取Trello板的JSON数据:

https://trello.com/b/nC8QJJoZ.json

这是我的代码:

 var https = require('https'); https.get('https://trello.com/b/nC8QJJoZ.json', function (res) { console.log('statusCode:', res.statusCode); console.log('headers:'); console.log(res.headers); res.setEncoding('utf8'); res.on('data', function (chunk) { console.log(chunk); }); }).on('error', function (e) { console.log('ERROR: ' + e); }); 

尽pipeURL在浏览器中完美工作,但它返回一个包含string“invalid key”的主体,其状态为401。 以下是输出:

 statusCode: 401 headers: { 'cache-control': 'max-age=0, must-revalidate, no-cache, no-store', 'x-content-type-options': 'nosniff', 'strict-transport-security': 'max-age=15768000', 'x-xss-protection': '1; mode=block', 'x-frame-options': 'DENY', 'x-trello-version': '1.430.0', 'x-trello-environment': 'Production', 'set-cookie': [ 'dsc=ae78a354044f982079cd2b5d8adc4f334cda679656b3539ee0adaaf019aee48e; Path= 'visid_incap_168551=/NYMaLRtR+qQu/H8GYry1BCKl1UAAAAAQUIPAAAAAAC1zWDD1JLPowdC 'incap_ses_218_168551=+/2JSB4Vz0XJO/pWbX4GAxCKl1UAAAAA0pAbbN5Mbs4tFgbYuskVPw expires: 'Thu, 01 Jan 1970 00:00:00', 'content-type': 'text/plain; charset=utf-8', 'content-length': '12', etag: 'W/"c-b1ec112"', vary: 'Accept-Encoding', date: 'Sat, 04 Jul 2015 07:24:00 GMT', 'x-iinfo': '1-11281210-11279245 PNNN RT(1435994639565 404) q(0 0 0 -1) r(3 3) U 'x-cdn': 'Incapsula' } invalid key 

我究竟做错了什么?

那么,事实certificate,我们需要提供Trello API应用程序密钥(从这里生成)与我们的请求。

 var https = require('https'); var KEY = '<replace this with your app key>'; https.get('https://trello.com/b/nC8QJJoZ.json?key=' + KEY, function (res) { ... }); 

这似乎是一个奇怪的要求,因为我们没有使用Trello的API端点 。 (即使我解决了这个问题,我仍然想知道为什么浏览器可以访问资源,但是服务器端脚本不能。)

Interesting Posts