You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让IIS 10.0的http.sys允许空内容POST请求?

解决WOPI客户端空内容POST请求触发http.sys 411错误的方案

针对Windows Server 2019 Version 1809 + IIS 10.0.17763.1环境下,WOPI客户端发送空内容POST请求被http.sys返回411 Length Required错误的问题,可通过以下服务器端配置解决,无需修改客户端代码:

1. 全局修改http.sys配置(适用于所有站点)

http.sys默认强制POST请求携带Content-Length头,可通过注册表禁用该检查:

  • 打开注册表编辑器,定位到HKLM\System\CurrentControlSet\Services\HTTP\Parameters
  • 新建DWORD(32位)值,命名为AllowZeroContentLength,设置值为1
  • 重启HTTP服务(执行命令 net stop http && net start http,注意此操作会重启所有依赖HTTP的服务,如IIS)

2. 针对WOPI路径配置URL Rewrite(更安全,仅影响WOPI请求)

通过IIS URL Rewrite模块为空内容POST请求添加Content-Length: 0头:

  1. 确保已安装IIS URL Rewrite模块
  2. 在WOPI Host站点的web.config中添加以下规则(替换/wopi/.*为你的实际WOPI请求路径):
<configuration>
  <system.webServer>
    <rewrite>
      <outboundRules>
        <rule name="Add Content-Length for empty WOPI POST" preCondition="Missing Content-Length">
          <match serverVariable="RESPONSE_Content-Length" pattern=".*" />
          <action type="Rewrite" value="0" />
          <conditions>
            <add input="{REQUEST_METHOD}" pattern="POST" />
            <add input="{REQUEST_URI}" pattern="/wopi/.*" />
          </conditions>
        </rule>
      </outboundRules>
      <preConditions>
        <preCondition name="Missing Content-Length">
          <add input="{REQUEST_CONTENT_LENGTH}" pattern="^$" />
        </preCondition>
      </preConditions>
    </rewrite>
  </system.webServer>
</configuration>

3. 在WOPI Host代码中处理(适用于自定义开发的WOPI Host)

如果你的WOPI Host是基于ASP.NET(Core/Framework)开发的,可在请求处理管道中提前处理空内容POST:

  • ASP.NET Core:添加中间件检查请求方法为POST且ContentLength为null时,设置Request.ContentLength = 0;
  • ASP.NET Framework:在Global.asax的BeginRequest事件中做类似处理

以上方案均无需针对每个WOPI客户端单独配置,服务器端配置完成后即可正常接收空内容POST请求。

内容的提问来源于stack exchange,提问作者0lli.rocks

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 21:35:14