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

    <small id='1SmVt'></small><noframes id='1SmVt'>

        • <bdo id='1SmVt'></bdo><ul id='1SmVt'></ul>

        <legend id='1SmVt'><style id='1SmVt'><dir id='1SmVt'><q id='1SmVt'></q></dir></style></legend>

        <tfoot id='1SmVt'></tfoot>
        <i id='1SmVt'><tr id='1SmVt'><dt id='1SmVt'><q id='1SmVt'><span id='1SmVt'><b id='1SmVt'><form id='1SmVt'><ins id='1SmVt'></ins><ul id='1SmVt'></ul><sub id='1SmVt'></sub></form><legend id='1SmVt'></legend><bdo id='1SmVt'><pre id='1SmVt'><center id='1SmVt'></center></pre></bdo></b><th id='1SmVt'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='1SmVt'><tfoot id='1SmVt'></tfoot><dl id='1SmVt'><fieldset id='1SmVt'></fieldset></dl></div>
      1. jQuery AJAX 調用導致錯誤狀態 403

        jQuery AJAX call results in error status 403(jQuery AJAX 調用導致錯誤狀態 403)

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

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

              <tbody id='xtG9G'></tbody>

              <tfoot id='xtG9G'></tfoot>
                <bdo id='xtG9G'></bdo><ul id='xtG9G'></ul>
                • <legend id='xtG9G'><style id='xtG9G'><dir id='xtG9G'><q id='xtG9G'></q></dir></style></legend>
                • 本文介紹了jQuery AJAX 調用導致錯誤狀態 403的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在使用 jQuery AJAX 對 Web 服務進行查詢.我的查詢如下所示:

                  I'm making a query to a web service using jQuery AJAX. My query looks like this:

                  var serviceEndpoint = 'http://example.com/object/details?version=1.1';
                  $.ajax({
                    type: 'GET', 
                    url: serviceEndpoint,
                    dataType: 'jsonp',
                    contentType: 'jsonp',
                    headers: { 'api-key':'myKey' },
                    success: onSuccess,
                    error: onFailure
                  });
                  

                  執行此操作時,我收到 403 狀態錯誤.我不明白為什么我的調用會導致狀態碼為 403.我控制著我的服務的安全性,它被標記為完全開放.我知道密鑰是有效的,因為我在另一個調用中使用它,它有效.這是有效的調用:

                  When I execute this, I get a status error of 403. I do not understand why my call results in having the status code 403. I'm in control of the security on my service and it is marked as wide-open. I know the key is valid, because I'm using it in another call, which works. Here is the call that works:

                  var endpoint = 'http://example.com/object/data/item?version=1.1';
                  $.ajax({ 
                    type: 'POST', 
                    url: endpoint, 
                    cache: 'false',
                    contentType:'application/json',
                    headers: {
                      'api-key':'myKey',
                      'Content-Type':'application/json'
                    },
                    data: JSON.stringify({
                      id: 5,
                      count:true
                    }),
                    success: onDataSuccess,
                    error: onDataFailure
                  });
                  

                  我知道這是兩個不同的端點.但我 100% 確信這不是服務器端身份驗證或權限錯誤.再一次,服務器端的一切都是開放的.這意味著我在客戶端請求上犯了一些錯誤.

                  I know these are two different endpoints. But I'm 100% convinced this is not a server-side authentication or permission error. Once again, everything is wide open on the server-side. Which implies that I'm making some mistake on my client-side request.

                  我覺得我應該傳達這個請求是在開發過程中提出的.所以,我從 http://localhost:3000 運行它.出于這個原因,我立即認為這是一個 CORS 問題.但一切看起來都是正確的.我的 POST 請求有效,但我的 GET 并沒有讓我感到非常沮喪.我錯過了什么嗎?會是什么?

                  I feel I should communicate that this request is being made during development. So, I'm running this from http://localhost:3000. For that reason, I immediately assumed it was a CORS issue. But everything looks correct. The fact that my POST request works, but my GET doesn't has me absolutely frustrated. Am I missing something? What could it be?

                  推薦答案

                  403錯誤的原因是你沒有發送headers.由于您正在發出 CORS 請求,因此您無法發送任何自定義標頭,除非服務器通過在響應中添加 Access-Control-Allow-Headers 來啟用這些標頭.

                  The reason of 403 error is you are not sending headers. Since you are making a CORS request, you cannot send any custom headers unless server enables these header by adding Access-Control-Allow-Headers to the response.

                  在 preflighted-request 中,客戶端向服務器發出 2 個請求.第一個是預檢(使用 OPTIONS 方法),第二個是真正的請求.服務器發送 Access-Control-Allow-Headers 標頭作為預檢請求的響應.因此,它可以發送一些標頭.通過這種方式,您的 POST 請求可以工作,因為 POST 請求是預檢請求.但是對于 GET 請求,沒有預檢來收集 Access-Control-Allow-Headers 標頭和瀏覽器在這種情況下不會發送您的自定義標頭.

                  In a preflighted-request, client makes 2 requests to the server. First one is preflight (with OPTIONS method) and the second one is the real request. The server sends Access-Control-Allow-Headers header as a response of the preflight request. So it enables some headers to be sent. By this way your POST request can work because the POST request is a preflight-request. But for a GET request, there is no preflight to gather Access-Control-Allow-Headers header and browser doesn't send your custom headers in this case.

                  解決此問題的方法:

                  作為一種解決方法,將您的 dataTypecontentType 設置為 json,如下所示:

                  As a workaround, set your dataType and contentType to json as the following:

                  var serviceEndpoint = 'http://example.com/object/details?version=1.1';
                  $.ajax({
                    type: 'GET', 
                    url: serviceEndpoint,
                    dataType: 'json',
                    contentType: 'json',
                    headers: { 'api-key':'myKey' },
                    success: onSuccess,
                    error: onFailure
                  });
                  

                  通過這種方式,您的獲取請求將是一個預檢請求.如果您的服務器使用 api-key" rel="nofollow noreferrer">Access-Control-Allow-Headers 標頭,它會起作用.

                  By this way, your get request will be a preflighted request. If your server enables the api-key with Access-Control-Allow-Headers header, it will work.

                  上述請求的示例服務器配置(用 express.js 編寫):

                  Sample server configuration for the above request (written in express.js):

                  res.setHeader('Access-Control-Allow-Origin', '*');
                  res.setHeader('Access-Control-Allow-Methods', '*');
                  res.setHeader('Access-Control-Allow-Headers', 'api-key,content-type');
                  res.setHeader('Access-Control-Allow-Credentials', true);
                  

                  添加:

                  實際上,contentType 應該是 application/javascriptapplication/json 在進行 jsonp 請求時.沒有 contentType 作為 jsonp.

                  Actually, contentType should be either application/javascript or application/json while doing a jsonp request. There is no contentType as jsonp.

                  這篇關于jQuery AJAX 調用導致錯誤狀態 403的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                  XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分
                  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 部分內容)
                  XmlHttpRequest onprogress interval(XmlHttpRequest onprogress 間隔)
                  <tfoot id='x61iy'></tfoot>
                    <i id='x61iy'><tr id='x61iy'><dt id='x61iy'><q id='x61iy'><span id='x61iy'><b id='x61iy'><form id='x61iy'><ins id='x61iy'></ins><ul id='x61iy'></ul><sub id='x61iy'></sub></form><legend id='x61iy'></legend><bdo id='x61iy'><pre id='x61iy'><center id='x61iy'></center></pre></bdo></b><th id='x61iy'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='x61iy'><tfoot id='x61iy'></tfoot><dl id='x61iy'><fieldset id='x61iy'></fieldset></dl></div>

                      <bdo id='x61iy'></bdo><ul id='x61iy'></ul>
                    • <legend id='x61iy'><style id='x61iy'><dir id='x61iy'><q id='x61iy'></q></dir></style></legend>

                          <tbody id='x61iy'></tbody>

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

                            主站蜘蛛池模板: 日本一区二区三区四区 | 日韩视频在线一区 | 在线观看中文视频 | 亚洲欧洲中文日韩 | 欧美综合在线视频 | 午夜欧美 | 亚洲va国产日韩欧美精品色婷婷 | 日韩在线观看 | 国产精品久久久久久久久免费高清 | 九九热在线视频 | 国产精品久久久精品 | 色偷偷人人澡人人爽人人模 | 毛片免费在线观看 | 国产中文字幕在线观看 | 午夜国产精品视频 | 精品日韩一区二区 | 在线免费看黄 | 免费精品| zzzwww在线看片免费 | 亚洲视频在线看 | 中文字幕日韩欧美一区二区三区 | 国产成人高清 | 毛片一区二区三区 | 欧美一级淫片免费视频黄 | 国产91在线 | 中日 | 国产乱码久久久久久一区二区 | 久久久精 | 亚洲色图插插插 | 日本在线一二 | 精品一区二区在线视频 | 亚洲在线久久 | 国产成人免费网站 | 亚洲网在线 | 欧美一区二区三区高清视频 | 亚洲导航深夜福利涩涩屋 | 亚洲国产网| 成人在线免费观看视频 | 精品久久久久久国产 | 欧美日韩在线一区二区 | 羞羞午夜| 中文字幕亚洲精品 |