• <small id='5wGrp'></small><noframes id='5wGrp'>

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

      <tfoot id='5wGrp'></tfoot>

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

        时间:2023-10-14
        <tfoot id='fEypq'></tfoot>

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

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

                  本文介绍了HTTP 预检 (OPTIONS) 请求仅在 IE 中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我尝试向我的 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 中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:禁止预检 403 响应 下一篇:从本地文件夹导入 type=module 的脚本会导致 CORS 问

                  相关文章

                  最新文章

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

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

                      <tfoot id='gKqzX'></tfoot>

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