在发送的WebRequest gzip压缩的数据? [英] Sending gzipped data in WebRequest?

查看:343
本文介绍了在发送的WebRequest gzip压缩的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的C#应用​​程序发送到我的Apache服务器安装mod_gzip的大量数据(〜100K)。我试图给gzip首先使用System.IO.Compression.GZipStream数据。 PHP接收原gzip压缩的数据,因此Apache不解压它,因为我期望的那样。 ?我失去了一些东西。



  System.Net.WebRequest REQ = WebRequest.Create(this.Url); 
req.Method = this.Method; //后
req.Timeout = this.Timeout;
req.Co​​ntentType =应用/的X WWW的形式,进行了urlencoded
req.Headers.Add(内容编码:gzip);

的System.IO.Stream reqStream = req.GetRequestStream();

GZipStream GZ =新GZipStream(reqStream,CompressionMode.Compress);

System.IO.StreamWriter SW =新System.IO.StreamWriter(GZ,Encoding.ASCII);
sw.Write(large_amount_of_data);
sw.Close();

gz.Close();
reqStream.Close()


System.Net.WebResponse RESP = req.GetResponse();
//(手柄的响应...)



我不能完全肯定内容-Encoding:gzip的适用于客户端提供的头文件


解决方案

关于你的问题是否内容编码适用于客户端提供的头 - 根据 HTTP / 1.1标准,它是:



(从第7节)




请求和响应消息可能会转移一个实体,如果没有其他由请求方法或响应状态代码的限制。




(从第7.1节)




 实体头=允许; 14.7节
|内容编码;第14.11
|内容语言;第14.12
|内容长度;第14.13
|内容位置;第14.14
|内容-MD5;第14.15
|内容范围;第14.16
|内容类型 ;第14.17
|过期;第14.21
|上一次更改 ;第14.29
|扩展头



I have a large amount of data (~100k) that my C# app is sending to my Apache server with mod_gzip installed. I'm attempting to gzip the data first using System.IO.Compression.GZipStream. PHP receives the raw gzipped data, so Apache is not uncompressing it as I would expect. Am I missing something?

System.Net.WebRequest req = WebRequest.Create(this.Url);
req.Method = this.Method; // "post"
req.Timeout = this.Timeout;
req.ContentType = "application/x-www-form-urlencoded";
req.Headers.Add("Content-Encoding: gzip");

System.IO.Stream reqStream = req.GetRequestStream();

GZipStream gz = new GZipStream(reqStream, CompressionMode.Compress);

System.IO.StreamWriter sw = new System.IO.StreamWriter(gz, Encoding.ASCII);
sw.Write( large_amount_of_data );
sw.Close();

gz.Close();
reqStream.Close()


System.Net.WebResponse resp = req.GetResponse();
// (handle response...)

I'm not entirely sure "Content-Encoding: gzip" applies to client-supplied headers.

解决方案

Regarding your question whether Content-Encoding is applicable to client-supplied headers - according to HTTP/1.1 standard, it is:

(from section 7)

Request and Response messages MAY transfer an entity if not otherwise restricted by the request method or response status code.

(from section 7.1)

   entity-header  = Allow                    ; Section 14.7
                  | Content-Encoding         ; Section 14.11
                  | Content-Language         ; Section 14.12
                  | Content-Length           ; Section 14.13
                  | Content-Location         ; Section 14.14
                  | Content-MD5              ; Section 14.15
                  | Content-Range            ; Section 14.16
                  | Content-Type             ; Section 14.17
                  | Expires                  ; Section 14.21
                  | Last-Modified            ; Section 14.29
                  | extension-header

这篇关于在发送的WebRequest gzip压缩的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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