3

我想将POST数据形成网络服务器的默认页面,例如:

POST http://errorreporting.example.com/ HTTP/1.1

我希望服务器负责302将客户端重定向到POST应该去的地方。服务器上的default.asp文件执行此任务(这是 Microsoft 推荐的技术),通过执​​行Redirect

默认.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到服务器时:

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
4

2 回答 2

3

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

XMLHttpRequest用来执行POSTs。几乎所有的实现XMLHttpRequest例如Chrome、Internet Explorer、MSXML)都有一个错误,它在重定向之后执行 a GET,而不是 a 。POST

W3C的XMLHttpReqest 规范说应该遵循重定向并重新发出请求:

如果响应是 HTTP 重定向:

如果重定向不违反安全性(例如同源),无限循环预防措施,并且支持该方案,则在遵守同源请求事件规则的同时透明地遵循重定向。

注意:HTTP 对用户代理在重定向期间保留请求方法请求实体主体提出了要求,并且还要求将某些类型的自动重定向通知最终用户。

是一个站点,您可以在其中测试浏览器XmlHttpRequest实现中的错误。


最后,我将解决一个IIS错误和一个XMLHttpRequest错误,方法是让我的“默认”页面执行所有操作302 redirect,但200 OK改为返回:

HTTP/1.1200 OK
Connection: close
Date: Sun, 27 Jun 2010 13:28:14 GMT
Server: Microsoft-IIS/6.0
Location: http://errorreporting.example.com/submit/SubmitError.ashx
Content-Length: 92
Content-Type: text/html
Cache-control: private

<HTML><BODY>This content has moved <A href="submit/SubmitError.ashx">here.</A></BODY></HTML>

无论如何,我都在强迫客户进行两次点击 - 还不如让它正常工作。

于 2010-06-27T13:35:51.613 回答
0

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

我安装了要求(应用程序请求写入URL 重写),然后添加了一个入站规则来将后端请求重写为 Express,但我一直收到 405(不允许方法)。

最终,我从Stefano Scerra 的博客中收集了一些想法。

这是我最终的 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>
于 2020-06-29T04:08:06.097 回答