Created
March 24, 2015 19:43
-
-
Save timgaunt/10613e3a095525155ca7 to your computer and use it in GitHub Desktop.
Make web request gzip'd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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