【发布时间】:2015-07-24 20:58:46
【问题描述】:
需要连接到external api: Vogogo。困难的部分是将 curl 示例转换为有效的 Meteor HTTP.get 调用。现在这是我想出的代码
apiversionVogogo = 'v3';
Vogogo.listAllCustomers = function() {
HTTP.get('https://api.vogogo.com/' + apiversionVogogo + '/customers', {
headers: {
'Authorization': {
user: clientID,
clientsecret: apisecret
}
}
},
function(error, result) {
if (error) {
console.log(error);
} else {
console.log(result);
}
});
return;
}
响应是一条错误消息:
error_message: 'HTTP Authorization expected"'
有人可以帮我将这个基本的 HTTP 身份验证改写成默认格式吗?在文档中,使用 CURL 给出了一个示例。
curl -X GET 'https://api.vogogo.com/v3/customers' \
--user clientsecret: \
-H "Content-Type: application/json"
【问题讨论】:
-
您是否尝试在选项字段中设置
auth参数,而不是在标题中实际设置Authorization?来自文档:auth String HTTP basic authentication string of the form "username:password" -
让你的请求看起来像
HTTP.get('https://api.vogogo.com/' + apiversionVogogo + '/customers', { auth : "clientID:apisecret"}) -
谢谢内特!这就像一个魅力:)
标签: javascript node.js meteor