久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <small id='4slKS'></small><noframes id='4slKS'>

    1. <i id='4slKS'><tr id='4slKS'><dt id='4slKS'><q id='4slKS'><span id='4slKS'><b id='4slKS'><form id='4slKS'><ins id='4slKS'></ins><ul id='4slKS'></ul><sub id='4slKS'></sub></form><legend id='4slKS'></legend><bdo id='4slKS'><pre id='4slKS'><center id='4slKS'></center></pre></bdo></b><th id='4slKS'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='4slKS'><tfoot id='4slKS'></tfoot><dl id='4slKS'><fieldset id='4slKS'></fieldset></dl></div>

    2. <tfoot id='4slKS'></tfoot>

      <legend id='4slKS'><style id='4slKS'><dir id='4slKS'><q id='4slKS'></q></dir></style></legend>

        <bdo id='4slKS'></bdo><ul id='4slKS'></ul>

      預(yù)檢中帶有 http 401 的 Ajax CORS 請求

      Ajax CORS Request with http 401 in preflight(預(yù)檢中帶有 http 401 的 Ajax CORS 請求)

      <tfoot id='tpU4s'></tfoot>

            <tbody id='tpU4s'></tbody>

          • <bdo id='tpU4s'></bdo><ul id='tpU4s'></ul>

                <small id='tpU4s'></small><noframes id='tpU4s'>

              1. <legend id='tpU4s'><style id='tpU4s'><dir id='tpU4s'><q id='tpU4s'></q></dir></style></legend>
                <i id='tpU4s'><tr id='tpU4s'><dt id='tpU4s'><q id='tpU4s'><span id='tpU4s'><b id='tpU4s'><form id='tpU4s'><ins id='tpU4s'></ins><ul id='tpU4s'></ul><sub id='tpU4s'></sub></form><legend id='tpU4s'></legend><bdo id='tpU4s'><pre id='tpU4s'><center id='tpU4s'></center></pre></bdo></b><th id='tpU4s'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='tpU4s'><tfoot id='tpU4s'></tfoot><dl id='tpU4s'><fieldset id='tpU4s'></fieldset></dl></div>
                本文介紹了預(yù)檢中帶有 http 401 的 Ajax CORS 請求的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我現(xiàn)在掙扎了好幾個小時.我想向另一個域發(fā)出一個簡單的 ajax 請求,但總是得到 http 401 錯誤:

                I am struggling for hours now. I want to make a simple ajax request to another domain, but get http 401 Error all the time:

                jQuery(document).ready(function($){
                  var challengeid = $('#codepressHook').data('challengeid');
                  var clicked = false;
                  $('#codepressHook').click(function(){
                    if(!clicked){
                      $.ajax({
                        url: "https://dev.radbonus.com/admin/affiliate-connections/retrieveSingle/"+challengeid+".json",
                        method: "GET",
                        dataType: "json",
                        jsonp: false,
                        contentType: "application/json",
                        xhrFields: {
                          withCredentials: true
                        },
                        beforeSend: function(xhr){
                          xhr.setRequestHeader("Authorization", "Basic "+ btoa(username+":"+password));
                        },
                        success: function(data){
                          $('#codepressHock').html(data.data.code);
                        },
                        error: function(error){
                          alert(error);
                        }
                      });
                    }
                  });
                });
                

                我在服務(wù)器端設(shè)置了所有相關(guān)的 CORS 標(biāo)頭.這是網(wǎng)絡(luò)流量:

                I set all relevant CORS headers on the serverside. Here is the network traffic:

                Request URL:https://dev.radbonus.com/admin/affiliate-connections/retrieveSingle/45.json
                Request Method:OPTIONS
                Status Code:401 Unauthorized
                Remote Address:185.102.94.230:443
                Referrer Policy:no-referrer-when-downgrade
                
                Response Headers
                view source
                Access-Control-Allow-Credentials:true
                Access-Control-Allow-Headers:Content-Type, X-Requested-With, Authorization, Origin
                Access-Control-Allow-Methods:POST, GET, PUT, DELETE, OPTIONS
                Access-Control-Allow-Origin:http://radbonus.com
                Access-Control-Max-Age:31536000
                Content-Length:463
                Content-Type:text/html; charset=iso-8859-1
                Date:Sat, 24 Jun 2017 11:25:33 GMT
                Server:Apache/2.4.18 (Ubuntu)
                WWW-Authenticate:Basic realm="Admin"
                
                Request Headers
                view source
                Accept:*/*
                Accept-Encoding:gzip, deflate, sdch, br
                Accept-Language:de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
                Access-Control-Request-Headers:authorization,content-type
                Access-Control-Request-Method:GET
                Connection:keep-alive
                Host:dev.radbonus.com
                Origin:http://radbonus.com
                Referer:http://radbonus.com/plugintest/
                User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
                

                我知道有很多關(guān)于這個主題的帖子,但似乎我缺少一些簡單的東西.誰能幫幫我?

                I know that there are a lot of posts on this topic, but it seems I'm missing something simple. Could anyone help me?

                推薦答案

                UPDATE 看來我說的不對.Authorization 標(biāo)頭永遠不會為 OPTIONS 請求發(fā)送.請參閱 sideshowbarker 的評論 - 您需要確保您的服務(wù)器不會以 401 響應(yīng) OPTIONS 請求.

                UPDATE Looks like I was not right. Authorization header is never sent for OPTIONS request. Please see comment by sideshowbarker - you need to make sure that your server doesn't respond with 401 to OPTIONS request.

                我不知道你的服務(wù)器是用什么語言編寫的,但是你以錯誤的方式實現(xiàn)了授權(quán) - OPTIONS 方法應(yīng)該從 auth 中排除.另請參閱此處 - OPTIONS 請求身份驗證

                I don't know what language is your server written in, but you implemented authorization in the wrong way - OPTIONS method should be excluded from auth. Also see here - OPTIONS request authentication

                以下是過時的答案:

                您的服務(wù)器端需要對該請求進行 HTTP 基本身份驗證.而且您不提供憑據(jù).401錯誤與CORS無關(guān);這只是意味著服務(wù)器選擇不授權(quán)您的請求,因為您沒有提供身份驗證憑據(jù).

                Your serverside requires HTTP Basic authentication for this request. And you don't provide credentials. 401 error has nothing to do with CORS; it just means that the server chose to not authorize your request because you didn't provide auth credentials.

                如果您嘗試打開此網(wǎng)址(如 https://dev.radbonus.com/admin/affiliate-connections/retrieveSingle/1.json) 直接在瀏覽器中,您將被要求輸入登錄名和密碼,這是瀏覽器使用 WWW-Authenticate 處理 401 錯誤的方式 標(biāo)題.

                If you try to open this url (like https://dev.radbonus.com/admin/affiliate-connections/retrieveSingle/1.json) directly in browser, you will be asked to enter login&password, which is how the browser handles 401 error with WWW-Authenticate header.

                請注意 Authorization 標(biāo)頭實際上并未包含在您的請求中.所以不要使用 beforeSend 鉤子,你應(yīng)該直接在你的調(diào)用中包含標(biāo)題:

                Please notice that Authorization header is actually not included with your request. So instead of using beforeSend hook, you should probably just include header directly in your call:

                headers: {
                    'Authorization': 'Basic ' + btoa(username+':'+password),
                },
                

                并確保 Authorization 標(biāo)頭出現(xiàn)在您的請求中.

                And make sure that Authorization header presents in your request.

                這篇關(guān)于預(yù)檢中帶有 http 401 的 Ajax CORS 請求的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調(diào)用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調(diào)用完成)
                JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標(biāo)頭) - IT屋-程序員軟件開發(fā)技術(shù)分
                Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內(nèi)容)
                  <bdo id='Nd4fz'></bdo><ul id='Nd4fz'></ul>

                    <legend id='Nd4fz'><style id='Nd4fz'><dir id='Nd4fz'><q id='Nd4fz'></q></dir></style></legend>
                          <tbody id='Nd4fz'></tbody>

                        <tfoot id='Nd4fz'></tfoot>

                        <small id='Nd4fz'></small><noframes id='Nd4fz'>

                      • <i id='Nd4fz'><tr id='Nd4fz'><dt id='Nd4fz'><q id='Nd4fz'><span id='Nd4fz'><b id='Nd4fz'><form id='Nd4fz'><ins id='Nd4fz'></ins><ul id='Nd4fz'></ul><sub id='Nd4fz'></sub></form><legend id='Nd4fz'></legend><bdo id='Nd4fz'><pre id='Nd4fz'><center id='Nd4fz'></center></pre></bdo></b><th id='Nd4fz'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Nd4fz'><tfoot id='Nd4fz'></tfoot><dl id='Nd4fz'><fieldset id='Nd4fz'></fieldset></dl></div>
                        1. 主站蜘蛛池模板: 夜夜爽99久久国产综合精品女不卡 | 天天射影院 | 国产精品视频www | 久久国产欧美日韩精品 | 永久看片 | 日本特黄a级高清免费大片 国产精品久久性 | 黄视频网站在线 | 在线成人| 刘亦菲国产毛片bd | 色一阁| 久草在线| 波多野结衣电影一区 | 成人网在线观看 | 操操日| 天天爱天天操 | 欧美国产日韩一区二区三区 | 日本三级播放 | 成人免费看电影 | 97伦理影院 | 国产精品久久精品 | 成人福利在线观看 | 国产香蕉视频 | 粉嫩av在线 | 不卡的av在线 | 九色在线观看 | 精品九九久久 | 国产人成在线观看 | 亚洲精品91 | 日韩精品视频一区二区三区 | 三级av在线| 国产最好的av国产大片 | 色女人天堂 | 亚洲一区二区三区免费在线 | 久久久123 | 欧美一区2区三区4区公司 | 99热热| 日韩av大片免费看 | 亚洲天堂久久 | 国产精品久久九九 | 亚洲+变态+欧美+另类+精品 | 成人在线观看免费 |