【问题标题】:Basic authentication : failure supergaent+OSX , success on superagent+Redhat , success on Postman+OSX,基本认证: supergaent+OSX 失败, superagent+Redhat 成功, Postman+OSX 成功,
【发布时间】:2017-02-25 02:48:20
【问题描述】:

使用 POSTMAN,一切都很好:

我将相同的标头、参数、...传递给 superagent,如下所示:

const superagent = require('superagent');
const grab = require('ps-grab');


superagent.get('https://x.rathath.net/issue_statuses.json')
    .set({
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    })
    .auth(grab('--user'),grab('--password'))
    .send({})
    .end((error,response)=>{
        console.log(response.text);
    });

但是失败了!

我有疑问: superagent+Authorization Header+ OSX .. 我的意思是这三个的兼容性。

确实,我在 Redhat 机器上运行了相同的 javascript sn-p,它运行良好。

【问题讨论】:

    标签: basic-authentication darwin superagent


    【解决方案1】:

    不同之处在于,您可能正在调用另一个域,而不是您的 js 应用程序正在运行的域。这称为 CORS。当您这样做时,结合身份验证,服务器需要返回 CORS 标头,说明:

    access-control-allow-credentials: true
    access-control-allow-origin: your-app-domain.here
    

    两个陷阱:

    • 在您的超级代理调用中忘记了 .withCredentials()。这不仅适用于 cookie,也适用于身份验证。
    • 服务器返回 * 而不是您的域,但不允许与身份验证结合使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-21
      • 2017-05-11
      • 1970-01-01
      • 2021-06-17
      相关资源
      最近更新 更多