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

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

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

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

        CORS POST 请求不起作用 - 选项(错误请求) - 不允许来源

        时间:2023-09-14

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

                <tbody id='pwjiD'></tbody>
              <legend id='pwjiD'><style id='pwjiD'><dir id='pwjiD'><q id='pwjiD'></q></dir></style></legend>
            • <tfoot id='pwjiD'></tfoot>

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

                • <i id='pwjiD'><tr id='pwjiD'><dt id='pwjiD'><q id='pwjiD'><span id='pwjiD'><b id='pwjiD'><form id='pwjiD'><ins id='pwjiD'></ins><ul id='pwjiD'></ul><sub id='pwjiD'></sub></form><legend id='pwjiD'></legend><bdo id='pwjiD'><pre id='pwjiD'><center id='pwjiD'></center></pre></bdo></b><th id='pwjiD'></th></span></q></dt></tr></i><div id='pwjiD'><tfoot id='pwjiD'></tfoot><dl id='pwjiD'><fieldset id='pwjiD'></fieldset></dl></div>
                  本文介绍了CORS POST 请求不起作用 - 选项(错误请求) - 不允许来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在获取跨域 POST 请求以访问最新 beta 2 版本中的 Api 控制器时遇到了很多麻烦.

                  Chrome(和其他浏览器)吐槽:

                  OPTIONS http://api.hybridwebapp.com/api/values 400(错误请求)发布 http://api.hybridwebapp.com/api/values 404(未找到)

                  它可能与

                  还有错误:

                  来源 http://hybridwebapp.com 不允许

                  这完全矛盾,就好像它忽略了标题一样.

                  解决方案

                  好的,我已经通过了.这一定是我遇到过的最奇怪的问题.以下是如何解决"它:

                  1. 继续像往常一样生活,直到突然无处可去对该域的 OPTIONS 请求开始返回 200 OK(而不是 400 Bad Request)并且 POST 永远不会发生(或者至少看起来没有'不是因为浏览器吞下了它)
                  2. 意识到 Fiddler 的 OPTIONS 响应中神秘地包含Access-Control-Allow-XXX"的重复项.
                  3. 尝试从您的 web.config 中删除以下语句,即使您清楚地记得尝试修复之前的问题但它不起作用:

                  删除这个:

                   <http协议><customHeaders><remove name="X-Powered-By"/><add name="Access-Control-Allow-Origin" value="http://mydomain.com"/><add name="Access-Control-Allow-Headers" value="Accept, Content-Type, Origin"/><add name="Access-Control-Allow-Methods" value="GET, PUT, POST, DELETE, OPTIONS"/></customHeaders></http协议>

                  因为你已经有了这个:

                   var enableCorsAttribute = new EnableCorsAttribute("http://mydomain.com","来源、内容类型、接受",获取、放置、发布、删除、选项");config.EnableCors(enableCorsAttribute);

                  道德:你只需要一个.

                  I'm having a lot of trouble getting a cross domain POST request to hit an Api controller in the latest beta 2 release.

                  Chrome (and other browsers) spit out:

                  OPTIONS http://api.hybridwebapp.com/api/values 400 (Bad Request)
                  POST http://api.hybridwebapp.com/api/values 404 (Not Found) 
                  

                  It may be related to this issue but I have applied that workaround and several other fixes such as web.config additions here

                  I've been banging my head with this for a while so I created a solution to reproduce the problem exactly.

                  Load the web app there will be 2 buttons one for GET one for POST and the response will appear next to the button. GET works. Cannot get POST to return successfully.

                  I'm able to get a hint at the cause from Fiddler but it makes no sense because if you look at the response it DOES include the domain in the Access-Controll-Allow-Origin header:

                  There is a folder in the solution called "ConfigurationScreenshots" with a few screenshots of the IIS configuration (website bindings) and Project properties configurations to make it as easy as possible to help me :)

                  EDIT: Don't forget to add this entry to host file (%SystemRoot%system32driversetc):

                   127.0.0.1     hybridwebapp.com  api.hybridwebapp.com
                  

                  **STATUS: ** It seems that some browsers like Chrome allow me to proceed with the POST regardless of the error message in the OPTIONS response (while others like Firefox don't). But I don't consider that solved.

                  Look at the Fidler screenshots of the OPTIONS request it has

                  Access-Control-Allow-Origin: http://hybridwebapp.com

                  And yet the error:

                  The origin http://hybridwebapp.com is not allowed

                  That is completely contradictory it's as if it's ignoring the header.

                  解决方案

                  Ok I got past this. This has got to be the strangest issue I've ever encountered. Here's how to "solve" it:

                  1. Continue on with life as usual until suddenly out of no where OPTIONS requests to this domain begin returning 200 OK (instead of 400 Bad Request) and POST never happens (or at least seems like it doesn't because the browser swallows it)
                  2. Realize that Fiddler's OPTIONS response mysteriously contains duplicates for "Access-Control-Allow-XXX".
                  3. Try removing the following statement from you web.config even though you clearly remember trying that to fix the previous issue and it not working:

                  Remove this:

                      <httpProtocol>
                         <customHeaders>
                           <remove name="X-Powered-By" />
                           <add name="Access-Control-Allow-Origin" value="http://mydomain.com" />
                           <add name="Access-Control-Allow-Headers" value="Accept, Content-Type, Origin" />
                           <add name="Access-Control-Allow-Methods" value="GET, PUT, POST, DELETE, OPTIONS" />
                         </customHeaders>
                      </httpProtocol>
                  

                  Because you already have this:

                   var enableCorsAttribute = new EnableCorsAttribute("http://mydomain.com",
                                                                     "Origin, Content-Type, Accept",
                                                                     "GET, PUT, POST, DELETE, OPTIONS");
                          config.EnableCors(enableCorsAttribute);
                  

                  Moral: You only need one.

                  这篇关于CORS POST 请求不起作用 - 选项(错误请求) - 不允许来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:即使允许几乎所有内容,ASP.NET 5/Core/vNext CORS 也无法正常工作 下一篇:Core 2.1 拒绝使用 Access-Control-Expose-Headers 响应:*

                  相关文章

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

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

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