IIS7拒绝分块编码的文件上传 [英] IIS7 refuses chunked-encoded file upload

查看:248
本文介绍了IIS7拒绝分块编码的文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a Windows/Apache2/PHP app that receives file using chunked encoding. The reason is that the file uploaded is dynamic and its length is not known before transfer. This has always worked fine out of the box.

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

Now I need to port the app to IIS7/PHP. The problem is that IIS fails to receive the chunked file: When file is uploaded, the server just does not respond at all. How do I solve this?

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

Note that in my test, I don't even use PHP. I simply have a .php extension because IIS refuses a POST on .htm file (which makes sense).

正如rupello在本回答中所建议的那样,我用cURL进行了测试,以确保我的客户不是破碎。 cURL也没有得到答案,虽然如果转移没有分块,一切正常。

As suggested by rupello in this answer, I made the test with cURL to make sure my client is not broken. cURL fails to get an answer as well, although it all works fine if transfer is not chunked.

我做了以下测试:

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>

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

This command does not return (stuck waiting for an answer)

curl.exe http://serveur/test.php --form "upfile=@text.txt" 
   -H "Transfer-Encoding: chunked" -H "Expect:"

注意: -H期待: 是要取消curl发布的期望100-Continue 。没有这个标题的结果是相同的,execpt当然是额外的往返。
发送:

Note: -H "Expect:" is to suppress the Expect 100-Continue issued by curl. The result is the same without this header, execpt of course an additional roundtrip. Sent:

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

问题:服务器没有返回任何内容。服务器看起来像是在等待。 curl不会返回。

Problem: Nothing returned by server. Server looks like it keeps waiting. curl does not return.

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

The same command without the chunk encoding works as expected:

已发送:

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--

服务器现在回复正确:

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>

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

The test on plain-vanilla LAMP server with the same files and requests work fine.

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

So how do I enable request chunk-encoding on IIS?

注意:我确实尝试了相关的ASP参数,没有可用:

Note: I did try the related ASP parameter, to no avail:

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"


推荐答案

根据HTTP 1.1 spec ,分块编码定义为服务器编码 - 即服务器以这种编码方式发送响应,而不是相反( Wiki 页面也说同样的内容。没有提到Server 接受分块编码请求,因此它没有在IIS中实现。

According to HTTP 1.1 spec, chunked encoding is defined as server encoding - i.e. server sending response in such encoding, not the other way around (Wiki page also says the same). There is no mention of Server accepting a chunked encoded request, hence it is not implemented in IIS.

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

Having said that, it seems that APACHE has implemented this while being outside HTTP spec.

这篇关于IIS7拒绝分块编码的文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆