• <tfoot id='k78Fp'></tfoot>

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

        <bdo id='k78Fp'></bdo><ul id='k78Fp'></ul>

    2. <legend id='k78Fp'><style id='k78Fp'><dir id='k78Fp'><q id='k78Fp'></q></dir></style></legend>
        <i id='k78Fp'><tr id='k78Fp'><dt id='k78Fp'><q id='k78Fp'><span id='k78Fp'><b id='k78Fp'><form id='k78Fp'><ins id='k78Fp'></ins><ul id='k78Fp'></ul><sub id='k78Fp'></sub></form><legend id='k78Fp'></legend><bdo id='k78Fp'><pre id='k78Fp'><center id='k78Fp'></center></pre></bdo></b><th id='k78Fp'></th></span></q></dt></tr></i><div id='k78Fp'><tfoot id='k78Fp'></tfoot><dl id='k78Fp'><fieldset id='k78Fp'></fieldset></dl></div>
      1. 已启用 CORS,但在 POST JSON 时,预检响应的 HTTP 状

        时间:2023-09-03
          <tbody id='R5YJy'></tbody>
      2. <tfoot id='R5YJy'></tfoot>

                  <bdo id='R5YJy'></bdo><ul id='R5YJy'></ul>
                • <small id='R5YJy'></small><noframes id='R5YJy'>

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

                  <legend id='R5YJy'><style id='R5YJy'><dir id='R5YJy'><q id='R5YJy'></q></dir></style></legend>
                  本文介绍了已启用 CORS,但在 POST JSON 时,预检响应的 HTTP 状态代码 404 无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我已经彻底搜索,但在我的特定情况下找不到此问题的解决方案.

                  I've searched thoroughly but cannot find a solution to this issue in my particular circumstance.

                  使用 Fiddler (POST) 的跨域服务调用正确执行并接收到数据.但是,通过浏览器 (Chrome) 我收到消息预检有无效的 HTTP 状态代码 404"

                  Cross-domain service calls using Fiddler (POST) execute correctly and the data is received. However, through the browser (Chrome) I am getting the message 'preflight has invalid HTTP status code 404'

                  我有一个 Web API 应用程序并安装了 CORS 并确保 web.config 文件中存在以下内容:

                  I have a Web API application and have installed CORS and ensured the following is present in the web.config file:

                  <system.webServer>
                      <handlers>
                        <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
                        <remove name="OPTIONSVerbHandler" />
                        <remove name="TRACEVerbHandler" />
                        <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
                      </handlers>
                      <httpProtocol>
                        <customHeaders>
                          <add name="Access-Control-Allow-Origin" value="*" />
                          <add name="Access-Control-Allow-Headers" value="Content-Type" />
                          <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
                        </customHeaders>
                      </httpProtocol>
                  </system.webServer>
                  

                  这里是 Ajax 调用:

                  Here is the Ajax call:

                  var secretKey = 'difusod7899sdfiertwe08wepifdfsodifyosey',
                      url = 'http://api.intrinsic.co.uk/api/v1/PTS/ActiveDrivers?api_key=098werolllfWnCbPGAuIXVOJidDHRfYcgxImMlxTXopuekXrSOqOWzEAIdeNTWGPQPpyHxgVGsFysGFKPzq';
                  
                    jQuery.ajax ({
                        url: url,
                        type: "POST",
                        data: JSON.stringify({ secretKey: secretKey}),
                        dataType: "json",
                        contentType: "application/json; charset=utf-8",
                        success: function(data){
                            var content = "<table class="container"><thead><tr><th>Driver Number</th><th>Timestamp</th><th>VRN</th><th>Latitude</th><th>Longitude</th><th>Track Link</th></tr></thead><tbody>";
                            $.each(data.ActiveDrivers.DriverLocationStatus, function (index, element) {
                                content += "<tr><td>" + element.DriverNumber + "</td>";
                                content += "<td>" + dateFormat(element.Timestamp, "d/m/yy") + " " + dateFormat(element.Timestamp, "h:MM TT") + "</td>";
                                content += "<td>" + element.VRN + "</td>";
                                content += "<td>" + element.CurrentLatitude + "</td>";
                                content += "<td>" + element.CurrentLongitude + "</td>";
                                content += "<td><a href="https://www.google.co.uk/maps/place//@" + element.CurrentLatitude + "," + element.CurrentLongitude + ",15z/" target='_blank'>Track &raquo;</a></td></tr>";
                            });
                            content += "</tbody></table>";
                            $( "#result" ).html( content );
                        }
                    });
                  

                  显然,可以完美地在同一个域上运行,并且如上所述,它可以使用 Fiddler.

                  Obviously, works on the same domain perfectly and, as mentioned, it works using Fiddler.

                  我确定是浏览器的预检选项检查对于应用程序/json"的内容类型失败,但我不知道如何修复它.

                  I'm certain it is the browser's preflight OPTIONS check that is failing for content-type of 'application/json' but I'm not sure how to fix it.

                  web.config 文件中是否缺少我应该添加的内容?

                  Is there something missing in the web.config file that I should add?

                  我已尝试删除内容类型"而没有任何影响.

                  I have tried removing 'content-type' with no affect.

                  我曾希望这篇文章 可以解决问题(看起来很有希望),但遇到了同样的错误:

                  I had hoped this article would solve the issue (it seemed promising) but the same error is encountered:

                  XMLHttpRequest cannot load [URL]. Response for preflight has invalid HTTP status code 404
                  

                  推荐答案

                  谢谢,但是在上述配置更改后出现405错误.

                  Thanks but getting 405 error,after the above config changes.

                  在 web api Global.asax 文件中添加以下代码后,它终于可以工作了

                  Finally it works after adding below code in web api Global.asax file

                  protected void Application_BeginRequest(Object sender, EventArgs e)
                      {
                          //HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
                          if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
                          {
                              HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache");
                              HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
                              HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
                              HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
                              HttpContext.Current.Response.End();
                          }
                      }
                  

                  这篇关于已启用 CORS,但在 POST JSON 时,预检响应的 HTTP 状态代码 404 无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:--disable-web-security 是否可以在 Chrome 中使用? 下一篇:Microsoft Edge 阻止了发送到同一专用网络 CIDR 中的

                  相关文章

                  最新文章

                  <legend id='I7i5X'><style id='I7i5X'><dir id='I7i5X'><q id='I7i5X'></q></dir></style></legend><tfoot id='I7i5X'></tfoot>

                      <bdo id='I7i5X'></bdo><ul id='I7i5X'></ul>

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

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