javascript 通过 setRequestHeader 授权

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11577979/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 13:43:35  来源:igfitidea点击:

Authorization through setRequestHeader

javascriptauthentication

提问by Anonymoose

I found this code which makes it possible to authenticate using setRequestheader and Ajax.

我发现这段代码可以使用 setRequestheader 和 Ajax 进行身份验证。

this.xmlDoc.setRequestHeader('Authorization','Basic ' + Base64.encode("User:Password"));

Unfortunatily I have no knowledge of Ajax and Base64 does not seem to be class or method I can reference. Is there an alternative for this Basic encryption? Or a simular encode function I can call from Javascript?

不幸的是,我对 Ajax 一无所知,而且 Base64 似乎不是我可以参考的类或方法。这种基本加密有替代方案吗?或者我可以从 Javascript 调用的模拟编码函数?

Thank you !

谢谢 !

采纳答案by just.another.programmer

You need a function to Base64 encode the User:Password string. See this questionwhich gives a couple of good options to do this in javascript.

您需要一个函数来对 User:Password 字符串进行 Base64 编码。请参阅此问题,它提供了在 javascript 中执行此操作的几个不错的选择。