【问题标题】:Meteor basic HTTP authenticationMeteor 基本 HTTP 身份验证
【发布时间】: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


【解决方案1】:

在选项字段中使用auth 参数,而不是在标题中实际设置授权。来自文档:auth String HTTP basic authentication string of the form "username:password"。你的请求看起来像:

HTTP.get('https://api.vogogo.com/' + apiversionVogogo + '/customers', { auth : "clientID:apisecret"})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-21
    • 2011-11-12
    • 2011-05-05
    • 1970-01-01
    • 2011-02-11
    • 2013-09-01
    • 2011-05-08
    • 2015-09-09
    相关资源
    最近更新 更多