我正在尝试通过 ajax jquery 向托管在 https 上的服务器发出管理请求。不知何故,标头身份验证参数未在请求中传递,我收到 401 错误。我无法传递标头授权信息,并且收到 401 未经授权的错误。如何在标头中传递授权?任何机构以前都遇到过这个问题,任何帮助将不胜感激。谢谢。
下面是我的ajax请求::::
$.ajax({
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("Authorization","Basic YWRtaW46YWRtaW4=");
xhrObj.setRequestHeader("Access-Control-Allow-Origin","*");
xhrObj.setRequestHeader("Access-Control-Allow-Methods","POST, GET, OPTIONS, PUT, DELETE");
xhrObj.setRequestHeader("Access-Control-Allow-Headers","Content-Type");
} ,
url: '/test.html',
type : "POST",
dataType : "json",
crossDomain: true,
xhrFields: {
withCredentials: true
},
contentType: "application/json" ,
data: {
'name' : 'test123456',
'description' : 'test' ,
'owner' : 'admin' ,
'accessRestriction' : 'VIEW'
},
cache : true,
success : function(service_data) {
alert("success");
},
error : function(msg) {
alert("error");
}
});