0

I am using SslStream class for some reason and I can't use WebClient Class instead.

as title I have a response with :

Transfer-Encoding: chunked
Content-Encoding: gzip

when I am trying to read response normally it gives the response header then characters like this : 1297 ?E?)ebM???X?kr

I tried to use GZipStream class :

    bytes = new Byte[256];
    data = null;
    i = 0;
    GZipStream gz = new GZipStream(stream, CompressionMode.Decompress);
    while ((i = gz.Read(bytes, 0, bytes.Length)) != 0)
    {
        // Translate data bytes to a ASCII string.
        data += System.Text.Encoding.ASCII.GetString(bytes, 0, i);
    }
    Debug.WriteLine(data);

But it gives exception of type 'System.IO.InvalidDataException' Additional information: The magic number in GZip header is not correct. Make sure you are passing in a GZip stream.

I tried to read header bytes first and and when start to read the body it gives the same exception

  • Possible related : http://stackoverflow.com/questions/2815721/net-is-it-possible-to-get-httpwebrequest-to-automatically-decompress-gzipd-re –  Jul 20 '16 at 01:18
  • I can't use WebRequest or WebClient , I need to work only with a SslStream – Damon Bowen Jul 20 '16 at 03:00

0 Answers0