【问题标题】:How to use browser's default basic auth dialog pop up in angular2如何在angular2中弹出浏览器默认的基本认证对话框
【发布时间】:2017-06-08 18:41:15
【问题描述】:

我在向服务器发出 http post 请求时收到上述错误(401 未经授权)。我发现许多在线资源建议拦截它并制作我自己的登录界面,但我想使用浏览器的默认登录界面进行基本身份验证。

如何在 angular2 中收到 401 未授权状态时弹出浏览器的默认基本身份验证对话框,而不是仅将其记录为错误?

【问题讨论】:

标签: angular basic-authentication http-status-code-401


【解决方案1】:

这里有同样的问题。使用 chrome:

var xhttp=new XMLHttpRequest();
          xhttp.withCredentials = true;
          xhttp.open("GET", "https://httpbin.org/basic-auth/user/passwd", true);
          xhttp.send();

使用“user”和“passwd”作为此端点的凭据。不知道您的代码,但异常显示 XMLHttpRequest。因此 withCredentials 应该可以完成这项工作

【讨论】:

    猜你喜欢
    • 2020-07-27
    • 1970-01-01
    • 1970-01-01
    • 2020-05-05
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 2012-07-19
    • 2012-01-29
    相关资源
    最近更新 更多