Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

You're treating the response as a UTF-8 encoded string. That's bound to fail with binary data like GZip. A quick fix is to use Encoding.GetEncoding("iso-8859-1") instead of UTF8 in StringToByteArray, and also pass this encoding to the StreamReader constructor in FetchURL.

That encoding maps bytes to codepoints one-to-one; see this answer on Stack Overflowthis answer on Stack Overflow.

A cleaner way would be to not switch back and forth between unicode characters (string, StreamReader) and binary data (byte[], MemoryStream) in the first place. Until you have unzipped the data, it does not constitute a "string" in any meaningful way.

You're treating the response as a UTF-8 encoded string. That's bound to fail with binary data like GZip. A quick fix is to use Encoding.GetEncoding("iso-8859-1") instead of UTF8 in StringToByteArray, and also pass this encoding to the StreamReader constructor in FetchURL.

That encoding maps bytes to codepoints one-to-one; see this answer on Stack Overflow.

A cleaner way would be to not switch back and forth between unicode characters (string, StreamReader) and binary data (byte[], MemoryStream) in the first place. Until you have unzipped the data, it does not constitute a "string" in any meaningful way.

You're treating the response as a UTF-8 encoded string. That's bound to fail with binary data like GZip. A quick fix is to use Encoding.GetEncoding("iso-8859-1") instead of UTF8 in StringToByteArray, and also pass this encoding to the StreamReader constructor in FetchURL.

That encoding maps bytes to codepoints one-to-one; see this answer on Stack Overflow.

A cleaner way would be to not switch back and forth between unicode characters (string, StreamReader) and binary data (byte[], MemoryStream) in the first place. Until you have unzipped the data, it does not constitute a "string" in any meaningful way.

Source Link
balpha Staff
  • 11k
  • 3
  • 29
  • 27

You're treating the response as a UTF-8 encoded string. That's bound to fail with binary data like GZip. A quick fix is to use Encoding.GetEncoding("iso-8859-1") instead of UTF8 in StringToByteArray, and also pass this encoding to the StreamReader constructor in FetchURL.

That encoding maps bytes to codepoints one-to-one; see this answer on Stack Overflow.

A cleaner way would be to not switch back and forth between unicode characters (string, StreamReader) and binary data (byte[], MemoryStream) in the first place. Until you have unzipped the data, it does not constitute a "string" in any meaningful way.