Skip to content

Instantly share code, notes, and snippets.

@timgaunt
Created March 24, 2015 19:43
Show Gist options
  • Save timgaunt/10613e3a095525155ca7 to your computer and use it in GitHub Desktop.
Save timgaunt/10613e3a095525155ca7 to your computer and use it in GitHub Desktop.
Make web request gzip'd
HttpWebRequest request = WebRequest.Create(i_Uri) as HttpWebRequest;
request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
response = request.GetResponse() as HttpWebResponse;
If(response.Headers.ToString().IndexOf("gzip") != -1)
{
//unzip;
}
private static void DecompressGzipStream(Stream i_GzipStream)
{
using (StreamReader reader = new StreamReader(i_GzipStream))
{
using (BufferedStream gzipStream = new BufferedStream(new GZipStream(reader.BaseStream, CompressionMode.Decompress)))
{
using (StreamReader gzipReader = new StreamReader(gzipStream))
{
string streamBody = gzipReader.ReadToEnd();
Console.WriteLine("File Content: " + streamBody);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment