【发布时间】:2016-07-02 16:04:12
【问题描述】:
又是我一个蹩脚的问题。我对正常工作的 Rattic 密码数据库 API 进行了以下调用:
curl -s -H 'Authorization: ApiKey myUser:verySecretAPIKey' -H 'Accept: text/json' https://example.com/passdb/api/v1/cred/\?format\=json
我试图在 NodeJS 中复制这个调用,但是以下返回空白:
var request = require('request');
url='https://example.com/passdb/api/v1/cred/?format=json';
request({
url: url,
method: 'POST',
headers: [
{ 'Authorization': 'ApiKey myUser:verySecretAPIKey' }
],
},
function (error, response, body) {
if (error) throw error;
console.log(body);
}
);
感谢任何帮助。
【问题讨论】:
-
你试过
GET吗? -
是的,body 变量仍然是空行(不是 null 或未定义):/