[英]How to pass the authorization in ajax CORS request in Firebug?
I am trying to making an admin request to a server that is hosted on https through ajax jquery. 我试图通过ajax jquery向https上托管的服务器发出管理员请求。 Somehow the header authentication parameters are not getting passed in the request and I get a 401 error .
不知何故,头部认证参数未在请求中传递,我收到401错误。 I am not able to pass the header authorization information and I am getting 401 unauthorized error .
我无法传递标头授权信息,我收到401未经授权的错误。 How do I pass the authorization in the header?
如何在标题中传递授权? Any body faced this issue before , any help would be appreciated.
以前任何机构都面临这个问题,任何帮助都会受到赞赏。 Thanks.
谢谢。
Below is my ajax request :::: 以下是我的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");
}
});
如果您在允许标头中提供content-type
,则还需要通过授权。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.