C#HttpWebRequest的 - 使用gzip的COM pression [英] C# HttpWebRequest - Using Gzip Compression

查看:117
本文介绍了C#HttpWebRequest的 - 使用gzip的COM pression的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个计划,使得很多HttpWebRequests的,和我读到有关使用gzip COM pression加快响应数据的下载。我知道gzip的是什么,以及它是如何工作的,但我不知道它是如何工作在C#。

I have a program which makes lots of HttpWebRequests, and I read about using gzip compression to speed up the downloading of the response data. I know what gzip is, and how it works, but I don't know how it works in C#.

让我们说我有一个简单的GET请求:

Let's say I have a simple GET request:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://google.com");
request.Method = "GET";
WebResponse response = request.GetResponse();

我怎么能做出响应数据进行COM pressed采用gzip?我怎样才能显示COM pressed大小,则未COM pressed大小?

How could I make the response data be compressed in gzip? How can I show the compressed size, and then the un-compressed size?

感谢

推荐答案

请确保你在你的要求,你能接受gzip压缩响应状态。所以,在你的code创建的要求,做到这一点:

Make sure you state in your request that you can accept gzip'd responses. So, after your code to create the request, do this:

request.Headers.Add("Accept-Encoding", "gzip");

这将告诉服务器返回它压缩,如果可以。

This will tell the server to return it zipped, if it can.

我觉得展会的规模差异,唯一的办法就是为t使2电话,其中一个COM pression,一个没有了,比较的返回响应流的长度。

The only way I can think to show the size difference would be t make 2 calls, one with compression and one not, and compare the length of the returned response streams.

这篇关于C#HttpWebRequest的 - 使用gzip的COM pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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