admin管理员组文章数量:1391934
I found this code which makes it possible to authenticate using setRequestheader and 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?
Thank you !
I found this code which makes it possible to authenticate using setRequestheader and 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?
Thank you !
Share Improve this question asked Jul 20, 2012 at 11:00 AnonymooseAnonymoose 2,4917 gold badges40 silver badges71 bronze badges 3- What kind of request are you trying to authorize? The code sample you gave adds authorization to an xmlhttprequest, is that what you're doing? – just.another.programmer Commented Jul 20, 2012 at 11:02
- Yes, sorry for not specifying. this.xmlDoc=!_isIE&&window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"); – Anonymoose Commented Jul 20, 2012 at 11:05
- 1 @user1365889 You could google javascript base64 encode which is what all the answers you get will have done – Esailija Commented Jul 20, 2012 at 11:13
1 Answer
Reset to default 2You need a function to Base64 encode the User:Password string. See this question which gives a couple of good options to do this in javascript.
本文标签: javascriptAuthorization through setRequestHeaderStack Overflow
版权声明:本文标题:javascript - Authorization through setRequestHeader - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744711636a2621162.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论