简体   繁体   English

如何在 401 响应中禁用浏览器的默认登录提示?

[英]How to disable browser's default login prompt on 401 response?

Is there ANY way to suppress the browser's login prompt on 401 response when using XmlHttpRequest.使用 XmlHttpRequest 时,是否有任何方法可以在 401 响应中抑制浏览器的登录提示。

 var req = new XMLHttpRequest(); req.open("POST", URL, true); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.onreadystatechange = function () { if (this.readyState == 4) { req.onreadystatechange = null; if (this.status == 200) { //alert("Action called successfully"); }else if(this.status == 401) { // } else { var error = JSON.parse(this.response); alert(error.Message); } } };

If the URL looks like this:如果 URL 如下所示:

http://www.example.com

You can pass the login credentials like this:您可以像这样传递登录凭据:

http://username:password@www.example.com/

Or you could try sending them in a header:或者您可以尝试在标题中发送它们:

req.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Twitter上使用XmlHttpRequest时,我可以在401响应上禁止浏览器的登录提示 - Can I suppress the browser’s login prompt on 401 response when using XmlHttpRequest with Twitter 如何防止 Chrome 中的登录提示出现 401 基本身份验证的未授权错误 - How to prevent login prompt in chrome for 401 Unauthorization error for Basic Authentication 如何禁用浏览器提示以记住密码 - How to disable browser prompt to remember the password 浏览器无响应,但在 postman 中得到 401 - No response in browser but getting 401 in postman 如何禁用浏览器提示以确认ASPX页面中的页面刷新? - How to disable browser prompt to confirm page refresh in an ASPX page? 如何禁用浏览器的默认右键菜单 - How to disable default right click menu of browser 如何使用 Javascript 禁用浏览器默认键绑定? - How to disable browser default keybindings with Javascript? 如何在浏览器中禁用退格按钮的默认行为 - How to disable the default behaviour of the backspace button in the browser 使用ajax登录时如何让浏览器提示保存密码 - How to let browser prompt save password when using ajax to login 如何使浏览器提示打开或保存Ajax响应 - How to get browser to prompt to open or save an ajax response
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM