簡體   English   中英

如何在Firebug中的ajax CORS請求中傳遞授權?

[英]How to pass the authorization in ajax CORS request in Firebug?

我試圖通過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");
       }
 });

如果您在允許標頭中提供content-type ,則還需要通過授權。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM