简体   繁体   中英

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. Somehow the header authentication parameters are not getting passed in the request and I get a 401 error . I am not able to pass the header authorization information and I am getting 401 unauthorized error . 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({
    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 ,则还需要通过授权。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM