|
From the server, you can request a compressed response(Gzip) to be send back. The following code explains what you should add and replace to enable this compression.
-
First add this: using System.IO.Compression;
-
Next add the following to the request headers:
webRequest.Headers.Add(System.Net.HttpRequestHeader.AcceptEncoding, "gzip");
-
After creating a response add this code to get the response stream:
StreamReader str;
if (webResponse.Headers.Get("Content-Encoding") != null &&
webResponse.Headers.Get("Content-Encoding").ToLower() == "gzip")
{
str = new StreamReader(new GZipStream(webResponse.GetResponseStream(), CompressionMode.Decompress));
}
else
{
str = new StreamReader(webResponse.GetResponseStream());
}
|
|