gzip HttpWebRequest

问题描述 投票:4回答:3

我正在通过HttpWebRequest提交包含大量内容的HTTP POST请求。我想gzip邮件内容。这可能吗?

是否必须将IIS 7配置为处理压缩内容?它已经被配置为提供压缩响应。

我尝试添加Content-Encoding = gzip标头并写入包装在GZipStream中的请求流,但服务器返回504(GatewayTimeout),这似乎很奇怪。

c# iis-7 httpwebrequest
3个回答
1
投票

绝大多数Web服务器不支持压缩的请求主体。可以将mod_deflate配置为在Apache上支持它,但实际上很少(因为zip炸弹很容易引起DoS攻击)。我不知道IIS解决方案。

如果您正在与自己的服务器进行通讯,那么当然没有什么可以阻止您在应用程序级别进行压缩。如果必须传递标准格式类型以供后端读取,则应选择multipart/form-data,因为URL编码会膨胀压缩的content参数的二进制数据。


4
投票

我不认为IIS7开箱即用地支持GZIP请求。这就是为什么。在我的IIS7计算机上,gzip.dll不导出解压缩方法。

c:\Windows\System32\inetsrv>c:\vc9\bin\dumpbin.exe  -exports gzip.dll
Microsoft (R) COFF/PE Dumper Version 9.00.30729.01
Copyright (C) Microsoft Corporation.  All rights reserved.


Dump of file gzip.dll

File Type: DLL

  Section contains the following exports for gzip.dll

    00000000 characteristics
    47919400 time date stamp Sat Jan 19 01:09:04 2008
        0.00 version
           1 ordinal base
           6 number of functions
           6 number of names

    ordinal hint RVA      name

          1    0 0000242D Compress
          2    1 00002E13 CreateCompression
          3    2 000065AE DeInitCompression
          4    3 000012EE DestroyCompression
          5    4 0000658D InitCompression
          6    5 000065B6 ResetCompression

  Summary

        1000 .data
        1000 .reloc
        1000 .rsrc
        6000 .text

我认为这代表gzip.dll发生了变化。我相信在以前的gzip.dll版本中,有12种导出方法,其中包括6种进行解压缩的方法。


0
投票

我遇到相同的错误。

通过在Web.config中添加executionTimeout解决:

<httpRuntime maxRequestLength="1048576" executionTimeout="300" />

ExecutionTimeout-在几秒钟上...

© www.soinside.com 2019 - 2024. All rights reserved.