<i id='RRmXa'><tr id='RRmXa'><dt id='RRmXa'><q id='RRmXa'><span id='RRmXa'><b id='RRmXa'><form id='RRmXa'><ins id='RRmXa'></ins><ul id='RRmXa'></ul><sub id='RRmXa'></sub></form><legend id='RRmXa'></legend><bdo id='RRmXa'><pre id='RRmXa'><center id='RRmXa'></center></pre></bdo></b><th id='RRmXa'></th></span></q></dt></tr></i><div id='RRmXa'><tfoot id='RRmXa'></tfoot><dl id='RRmXa'><fieldset id='RRmXa'></fieldset></dl></div>

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

      1. <tfoot id='RRmXa'></tfoot>

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

        HTTP 预检 (OPTIONS) 请求仅在 IE 中失败

        HTTP preflight (OPTIONS) request fails in IE only(HTTP 预检 (OPTIONS) 请求仅在 IE 中失败)
            <bdo id='NaRtv'></bdo><ul id='NaRtv'></ul>
              <tbody id='NaRtv'></tbody>

                <i id='NaRtv'><tr id='NaRtv'><dt id='NaRtv'><q id='NaRtv'><span id='NaRtv'><b id='NaRtv'><form id='NaRtv'><ins id='NaRtv'></ins><ul id='NaRtv'></ul><sub id='NaRtv'></sub></form><legend id='NaRtv'></legend><bdo id='NaRtv'><pre id='NaRtv'><center id='NaRtv'></center></pre></bdo></b><th id='NaRtv'></th></span></q></dt></tr></i><div id='NaRtv'><tfoot id='NaRtv'></tfoot><dl id='NaRtv'><fieldset id='NaRtv'></fieldset></dl></div>

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

                • <tfoot id='NaRtv'></tfoot>
                  <legend id='NaRtv'><style id='NaRtv'><dir id='NaRtv'><q id='NaRtv'></q></dir></style></legend>
                • 本文介绍了HTTP 预检 (OPTIONS) 请求仅在 IE 中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我尝试向我的 REST API 发出 POST 请求.这是代码片段(使用 AngularJS):

                   $http({方法:'POST',网址:网址,数据:reqBody,标题:{内容类型":应用程序/json"}}).then(函数(响应){...}).catch(函数 (错误) {...});

                  根据

                  问题是,HTTP 选项响应包含浏览器处理实际 HTTP 请求所需的一切.

                  解决方案

                  我找到了所有这些混乱的原因.

                  API 服务和网站位于同一个域中,但在不同的端口上.具体来说,API 服务位于:

                  <块引用>

                  myDomain.com/apiService

                  网站位于:

                  <块引用>

                  myDomain.com:44443/webSite

                  因此,当网络浏览器从以下位置初始化调用时:

                  myDomain.com:44443/webSite/page1

                  到:

                  myDomain.com/apiService/service1

                  由于 CORS,Internet Explorer 阻止了调用.出于某种原因,Chrome 在这方面没有那么严格,因为它成功地调用了 API.

                  为了使其在 Internet Explorer 中运行,我将网站移至与 API 相同的端口:

                  <块引用>

                  myDomain.com/apiService

                  myDomain.com/webSite

                  I trying to make a POST request to my REST API. Here is the code snippet (using AngularJS):

                          $http({
                              method: 'POST',
                              url: url,
                              data: reqBody,
                              headers: {
                                  'content-type': 'application/json'
                              }
                          })
                          .then(function (response) {...})
                          .catch(function (error) {...});
                  

                  According to this article, because of the HTTP header

                  'content-type': 'application/json'

                  browser concludes that it will have to make an "not-simple" HTTP request which requires handshake with a server (HTTP options request will be sent before actual HTTP request).

                  Chrome handles the request like a charm, but IE (11 in my case) fails with the following messages:

                  The thing is, HTTP options response contains everything the browser needs to proceed with the actual HTTP request.

                  解决方案

                  I found the reason for all that mess.

                  The API service and the website were located on the same domain, but on different ports. To be specific, the API service was located on:

                  myDomain.com/apiService

                  and the website was located on:

                  myDomain.com:44443/webSite

                  Thus, when the web browser was initializing the call from:

                  myDomain.com:44443/webSite/page1

                  to:

                  myDomain.com/apiService/service1

                  Internet Explorer was blocking the call because of the CORS. For some reason, Chrome was less strict in that matter, because it succeeded to make the call to the API.

                  To make it work in Internet Explorer, I moved the website to the same port as the API:

                  myDomain.com/apiService

                  myDomain.com/webSite

                  这篇关于HTTP 预检 (OPTIONS) 请求仅在 IE 中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  SCRIPT5: Access is denied in IE9 on xmlhttprequest(SCRIPT5:在 IE9 中对 xmlhttprequest 的访问被拒绝)
                  XMLHttpRequest module not defined/found(XMLHttpRequest 模块未定义/未找到)
                  Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
                  How can I open a JSON file in JavaScript without jQuery?(如何在没有 jQuery 的情况下在 JavaScript 中打开 JSON 文件?)
                  How do I get the HTTP status code with jQuery?(如何使用 jQuery 获取 HTTP 状态码?)
                  quot;Origin null is not allowed by Access-Control-Allow-Originquot; in Chrome. Why?(“Access-Control-Allow-Origin 不允许 Origin null在铬.为什么?)
                  <i id='KzpC0'><tr id='KzpC0'><dt id='KzpC0'><q id='KzpC0'><span id='KzpC0'><b id='KzpC0'><form id='KzpC0'><ins id='KzpC0'></ins><ul id='KzpC0'></ul><sub id='KzpC0'></sub></form><legend id='KzpC0'></legend><bdo id='KzpC0'><pre id='KzpC0'><center id='KzpC0'></center></pre></bdo></b><th id='KzpC0'></th></span></q></dt></tr></i><div id='KzpC0'><tfoot id='KzpC0'></tfoot><dl id='KzpC0'><fieldset id='KzpC0'></fieldset></dl></div>

                  1. <small id='KzpC0'></small><noframes id='KzpC0'>

                    <legend id='KzpC0'><style id='KzpC0'><dir id='KzpC0'><q id='KzpC0'></q></dir></style></legend>

                      <bdo id='KzpC0'></bdo><ul id='KzpC0'></ul>
                        <tbody id='KzpC0'></tbody>
                        <tfoot id='KzpC0'></tfoot>