-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Steps to reproduce
- Install Windows Server Nano (10.0.14393)
- Connect to the server using PS Remoting, then use PowerShell Core (the built-in version) to download a file, e.g. try to download .NET Core 1.1 ZIP package:
Invoke-Webrequest -Uri 'https://go.microsoft.com/fwlink/?LinkID=835028' -OutFile C:\netcore11.zip -MaximumRedirection 10
Expected behavior
File is downloaded, HTTP 302 Redirect returned by go.microsoft.com is handled properly.
Actual behavior
The following error occurs:
invoke-webrequest : Response status code does not indicate success: 302 (Moved Temporarily).
And there is no workaround, because the thrown exception is a HttpRequestException thrown by EnsureSuccessStatusCode(), which loses all header information (so, unable even to access the Location header).
Issue is still present in the master branch:
https://github.com/PowerShell/PowerShell/blob/master/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/CoreCLR/WebRequestPSCmdlet.CoreClr.cs#L352
EnsureSuccessStatusCode() should not be used, as it doesn't support redirects, and it also obfuscates the exception, making it impossible to access the returned headers/body even if the exception is caught.
Environment data
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
BuildVersion 10.0.14393.1000
SerializationVersion 1.1.0.1
PSVersion 5.1.14393.1000
PSEdition Core
WSManStackVersion 3.0
CLRVersion