Hot answers tagged gzip
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. ...
Here is the relevant section of code from stack.PHP. $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_ENCODING,'gzip'); // Needed by API curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); $data = curl_exec($ch);
The API documentation states that the API always returns a compressed response: ...we guarantee that all responses are compressed, either with GZIP or DEFLATE. GZIP is the default. This means that you must send the results from wget to gunzip. Like so: wget -O- <URL> | gunzip > results.json Or, in your specific example: wget -O- ...
gzuncompress is for ZLIB not GZIP. The two algorithms are related, but not identical. gzuncompress isn't strictly guaranteed to decompress all ZLIB streams actually, its just guaranteed to decode the results of gzcompress. Which is honestly really weird. The appropriate function is gzdecode. If that's not available, http_inflate should also work.
Only top voted, non community-wiki answers of a minimum length are eligible