IIS7拒绝分块编码的文件上传

Ser*_*ier 5 php iis iis-7 chunked-encoding

我有一个Windows/Apache2/PHP应用程序,使用分块编码接收文件.原因是上传的文件是动态的,并且在传输之前它的长度是未知的.这一直都很好用.

现在我需要将应用程序移植到IIS7/PHP.问题是IIS无法接收分块文件:上传文件时,服务器根本没有响应.我该如何解决这个问题?

请注意,在我的测试中,我甚至不使用PHP.我只是有一个.php扩展名,因为IIS拒绝.htm文件上的POST(这是有意义的).

正如rupello在这个答案中所建议的那样,我用cURL进行了测试,以确保我的客户端没有被破坏.cURL也没有得到答案,尽管如果转移没有分块,一切正常.

我做了以下测试:

test.php的:

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf8" />
  </head>
  <body>
    <form method="post" enctype="multipart/form-data">
      File: <input type="file" name="upfile" />
      <input type="submit" value="go"/>
  </form>
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

此命令不返回(等待答案卡住)

curl.exe http://serveur/test.php --form "upfile=@text.txt" 
   -H "Transfer-Encoding: chunked" -H "Expect:"
Run Code Online (Sandbox Code Playgroud)

注意:-H "Expect:"是压制Expect 100-Continuecurl发出的.没有这个标题的结果是相同的,execpt当然是额外的往返.发送:

POST http://serveur/test.php HTTP/1.1
User-Agent: curl/7.15.3 (i586-pc-mingw32msvc) libcurl/7.15.3 zlib/1.2.2
Host: serveur
Pragma: no-cache
Accept: */*
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: multipart/form-data; boundary=----------------------------310dbcc6761b

8c
------------------------------310dbcc6761b
Content-Disposition: form-data; name="upfile"; filename="text.txt"
Content-Type: text/plain


5
hello
30

------------------------------310dbcc6761b--

0
Run Code Online (Sandbox Code Playgroud)

问题:服务器没有返回任何内容.服务器看起来像是在等待.卷曲不归.

没有块编码的相同命令按预期工作:

发送:

POST http://serveur/test.php HTTP/1.1
User-Agent: curl/7.15.3 (i586-pc-mingw32msvc) libcurl/7.15.3 zlib/1.2.2
Host: serveur
Pragma: no-cache
Accept: */*
Connection: Keep-Alive
Content-Length: 193
Content-Type: multipart/form-data; boundary=----------------------------e2d761bc173a

------------------------------e2d761bc173a
Content-Disposition: form-data; name="upfile"; filename="text.txt"
Content-Type: text/plain

hello
------------------------------e2d761bc173a--
Run Code Online (Sandbox Code Playgroud)

服务器现在正确回复:

HTTP/1.1 200 OK
Content-Type: text/html
Server: Microsoft-IIS/7.5
X-Powered-By: PHP/5.3.8
X-Powered-By: ASP.NET
Date: Mon, 21 Nov 2011 10:47:57 GMT
Content-Length: 272

<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf8" />
</head>
<body>
  <form method="post" enctype="multipart/form-data">
    File: <input type="file" name="upfile" />
    <input type="submit" value="go"/>
  </form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

对具有相同文件和请求的普通LAMP服务器的测试工作正常.

那么如何在IIS上启用请求块编码?

注意:我确实尝试过相关的ASP参数,但无济于事:

C:\...\inetsrv>appcmd.exe set config /section:asp /enableChunkedEncoding:True
Applied configuration changes to section "system.webServer/asp" for "MACHINE/
WEBROOT/APPHOST" at configuration commit path "MACHINE/WEBROOT/APPHOST"
Run Code Online (Sandbox Code Playgroud)

Ali*_*tad 0

根据 HTTP 1.1规范,分块编码被定义为服务器编码- 即服务器以这种编码发送响应,而不是相反(维基页面也这么说)。没有提到服务器接受分块编码请求,因此它没有在 IIS 中实现。

话虽如此,APACHE 似乎已经在 HTTP 规范之外实现了这一点。

  • 这真的是正确的吗?许多消息来源提到客户也可以使用它(特别是随着对大型上传的需求不断增加 - 邮件附件、上传图片等)。此外,看起来持久 HTTP 连接可能会受益于此功能。 (3认同)