More info / Docs :
- REST API's GZip response body isn't decoded @ /powershell/powershell/issues
- Discord thread
- Unable to override Accept-Encoding header with Invoke-WebRequest in version 7.4.1 #21205
- [System.Net.Http.HttpClientHandler.
AutomaticDecompression]
OP was using the same Invoke-WebRequest|RestMethod code on Ps5 and Ps7 with different results.
- One returned text
- The other was still gzipped
Here's a standalone test for 5 and 7. By changing, or omitting AutomaticDecompression -- you can reproduce similar output.
The first link compares additional headers:
Content-TypeContent-EncodingAccept-Encoding
Accept-Encoding: gzip, deflate, br- works when
AutomaticDecompressionisGzip - breaks when
AutomaticDecompressionisDeflateor not set
$handler = [Net.Http.HttpClientHandler]::new()
# $handler.AutomaticDecompression = [Net.DecompressionMethods]::GZip
# $handler.AutomaticDecompression = [Net.DecompressionMethods]::Deflate
$client = [Net.Http.HttpClient]::new( $handler )
$response = $client.GetAsync('https://postman-echo.com/gzip').GetAwaiter().GetResult()
$response.Content.Headers
$response.Content.ReadAsStringAsync().GetAwaiter().GetResult()- breaks when
AutomaticDecompressionis not set - works when
AutoMaticDecompressionisAllorGzip
$handler = [Net.Http.HttpClientHandler]::new()
# $handler.AutomaticDecompression = [Net.DecompressionMethods]::GZip
# $handler.AutomaticDecompression = [Net.DecompressionMethods]::All
$client = [Net.Http.HttpClient]::new( $handler )
$response = $client.GetAsync('https://postman-echo.com/gzip').GetAwaiter().GetResult()
$response.Content.Headers
$q = $response.Content.ReadAsStream()
[Text.Encoding]::GetEncoding('utf-8').GetString( $q.ToArray() )WinPS5> [Net.Http.HttpClientHandler].Assembly
GAC Version Location
--- ------- --------
True v4.0.30319 C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll
Pwsh7.4.5> [Net.Http.HttpClientHandler].Assembly.FullName
System.Net.Http, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a