大佬教程收集整理的这篇文章主要介绍了https – 如何使用基本身份验证进行dojo.request.xhr GET请求,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如何以及在何处在Dojo XHR选项中包含用户名和密码?
require(["dojo/request/xhr"],function(xhr){ xhr("example.json",{ // Include User and password options here ? user: "userLogin" password: "userpassword" handleAs: "json" }).then(function(data){ // Do something with the handled data },function(err){ // Handle the error condition },function(evt){ // Handle a progress event from the request if the // browser supports XHR2 }); });
谢谢.
在以前的Dojo版本中,这是有记录的,但现在似乎并非如此.但是,我刚刚测试了它,似乎在URL中添加了用户名和密码,例如:
http://user:password@myUrl/example.json
通常,浏览器应该能够翻译此URL,以便设置请求标头.
您也可以手动设置这些标头,例如使用:
xhr("example.json",{ headers: { "Authorization": "Basic " + base64.encode(toByteArray(user + ":" + pass)) } }).then(function(data) { // Do something });
但是,这需要dojox / encoding / base64模块和以下功能:
var toByteArray = function(str) { var bytes = []; for (var i = 0; i < str.length; ++i) { bytes.push(str.charCodeAt(i)); } return bytes; };
以上是大佬教程为你收集整理的https – 如何使用基本身份验证进行dojo.request.xhr GET请求全部内容,希望文章能够帮你解决https – 如何使用基本身份验证进行dojo.request.xhr GET请求所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。