发布到默认页面时IIS:405(不允许使用方法)

发布到默认页面时IIS:405(不允许使用方法),iis,post,http-status-code-405,Iis,Post,Http Status Code 405,我想将表单数据发布到web服务器的默认页面,例如: POST http://errorreporting.example.com/ HTTP/1.1 我希望服务器负责302将客户端重定向到POST应该去的地方。服务器上的default.asp文件通过执行重定向来执行此任务(): default.asp: <% Response.Redirect "SubmitError.ashx" %> 我从服务器获得了预期的响应: GET http://errorreporting.ex

我想
表单数据发布到web服务器的默认页面,例如:

POST http://errorreporting.example.com/ HTTP/1.1
我希望服务器负责
302
将客户端重定向到
POST
应该去的地方。服务器上的
default.asp
文件通过执行
重定向来执行此任务():

default.asp:

<%
   Response.Redirect "SubmitError.ashx"
%>
我从服务器获得了预期的响应:

GET http://errorreporting.example.com/ HTTP/1.1
HTTP/1.1 302 Object moved
Server: Microsoft-IIS/5.0
Location: SubmitError.ashx
...
POST http://errorreporting.example.com/ HTTP/1.1
但是当我
向服务器发布
时:

GET http://errorreporting.example.com/ HTTP/1.1
HTTP/1.1 302 Object moved
Server: Microsoft-IIS/5.0
Location: SubmitError.ashx
...
POST http://errorreporting.example.com/ HTTP/1.1
服务器对我非常生气:

HTTP/1.1 405 Method not allowed
Connection: close
Allow: OPTIONS, TRACE, GET, HEAD
...
我希望服务器能够将客户端重定向到相应的提交
URL
,而不是使用URL对客户端进行硬编码。当然,这是因为URL可能(即已经)更改:

  • http://errorreporting.example.com/SubmitError.asp
  • http://errorreporting.example.com/SubmitError.aspx
  • http://errorreporting.example.com/SubmitError.ashx
  • http://errorreporting.example.com/ErrorReporting/Submit.ashx
  • http://errorreporting.example.com/submiterror.php
  • http://errorreporting.example.com/submit/submiterror.ashx
等等

注意:如果我更改
URL
以包含文档位置:

/* SErrorReportingUrl = 'http://www.example.com:8088/ErrorReporting/SubmitError.ashx';
   SErrorReportingUrl = 'http://www.example.com/ErrorReporting/SubmitError.ashx';
   SErrorReportingUrl = 'http://errorreporting.example.com:8088/ErrorReporting/SubmitError.ashx';
   SErrorReportingUrl = 'http://errorreporting.example.com/SubmitError.ashx';
   SErrorReportingUrl = 'http://errorreporting.example.com';
   SErrorReportingUrl = 'http://errorreporting.example.com/SubmitError.ashx'; 
*/
   SErrorReportingUrl = 'http://errorreporting.example.com/submit/SubmitError.ashx';
它工作得很好:

HTTP/1.1 200 OK

事实证明,让IIS支持
POST
并没有真正的帮助

我正在使用
XMLHttpRequest
执行
POST
s。几乎所有
XMLHttpRequest
的实现(例如,Chrome、internetexplorer、MSXML)都有一个bug,在重定向后执行
GET
,而不是
POST

声明应遵循重定向并重新发布请求:

如果响应是HTTP重定向:

如果重定向没有违反安全性 (例如, 无限循环预防措施,以及 方案得到支持,透明 观察时遵循重定向 这个

注意:HTTP将要求放在用户身上 关于保护财产的代理人 和在重定向期间,以及 要求通知最终用户 某些自动变速器 重定向

您可以在浏览器的
XmlHttpRequest
实现中测试bug


最后,我将解决一个IIS错误和一个
XMLHttpRequest
错误,让我的“默认”页面执行
302重定向所需的所有操作,但返回
200 OK

HTTP/1.1
200正常

连接:关闭

日期:2010年6月27日星期日13:28:14 GMT

服务器:Microsoft IIS/6.0

位置:http://errorreporting.example.com/submit/SubmitError.ashx

内容长度:92

内容类型:text/html

缓存控制:专用

<HTML><BODY>This content has moved <A href="submit/SubmitError.ashx">here.</A></BODY></HTML>
此内容已移动

我强制客户端执行两次点击操作-最好让它正常工作。

我正在Express/Node上运行Vue.js。后端正在服务器端口3300上运行,但我们不想公开它

我安装了需求(和),然后添加了一个入站规则来重写要表达的后端请求,但我一直得到405(不允许使用方法)

最后,我通过从中收集一些想法使它得以进行

这是我最后的web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Handle History Mode and custom 404/500" stopProcessing="true">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/(api)" negate="true"/>
          </conditions>
          <action type="Rewrite" url="/" />
        </rule>
        <rule name="api" stopProcessing="true">
            <match url="^api/(.*)$" />
            <action type="Rewrite" url="http://10.1.1.217:3300/{R:1}" logRewrittenUrl="true" />
        </rule>
      </rules>
    </rewrite>
        <tracing>
            <traceFailedRequests>
                <add path="*">
                    <traceAreas>
                        <add provider="WWW Server" areas="Filter" verbosity="Verbose" />
                    </traceAreas>
                    <failureDefinitions timeTaken="00:00:00" statusCodes="100-999" />
                </add>
            </traceFailedRequests>
        </tracing>
  </system.webServer>
</configuration>