最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Authorization through setRequestHeader - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 2

You 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.

发布评论

评论列表(0)

  1. 暂无评论