You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Invoke-WebRequest / Invoke-RestMethod fails to follow HTTP redirects from HTTPS #2896
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:
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).
After some debugging, it looks like the root cause is that .NET Core's HttpClientHandler silently refuses to follow HTTPS-to-HTTP redirects.
However, there should be some way to at least look at the underlying response headers - currently, only a generic string description of the error is provided in the caught Exception (in desktop PowerShell - it is possible to retrieve the headers).
changed the title [-]Invoke-WebRequest / Invoke-RestMethod fails to follow HTTP redirects (Windows Server Nano)[/-][+]Invoke-WebRequest / Invoke-RestMethod fails to follow HTTP redirects[/+]on Mar 15, 2017
changed the title [-]Invoke-WebRequest / Invoke-RestMethod fails to follow HTTP redirects[/-][+]Invoke-WebRequest / Invoke-RestMethod fails to follow HTTP redirects from HTTPS[/+]on Mar 15, 2017
Activity
aburlak commentedon Dec 16, 2016
After some debugging, it looks like the root cause is that .NET Core's HttpClientHandler silently refuses to follow HTTPS-to-HTTP redirects.
However, there should be some way to at least look at the underlying response headers - currently, only a generic string description of the error is provided in the caught Exception (in desktop PowerShell - it is possible to retrieve the headers).
SteveL-MSFT commentedon Mar 15, 2017
Perhaps we should add a
-AllowRedirectToHTTPfromHTTPStype switch or just output a warning message[-]Invoke-WebRequest / Invoke-RestMethod fails to follow HTTP redirects (Windows Server Nano)[/-][+]Invoke-WebRequest / Invoke-RestMethod fails to follow HTTP redirects[/+]SteveL-MSFT commentedon Mar 15, 2017
This repros with alpha.17 on Ubuntu16 so not Nano specific
[-]Invoke-WebRequest / Invoke-RestMethod fails to follow HTTP redirects[/-][+]Invoke-WebRequest / Invoke-RestMethod fails to follow HTTP redirects from HTTPS[/+]SteveL-MSFT commentedon Mar 15, 2017
@PowerShell/powershell-committee suggests
-allowInsecureRedirect34 remaining items
tsteven4 commentedon Jan 4, 2021
In the mean time:
C:\Windows\System32\curl -L -o outfile "https://example.com/somefile"
mkht commentedon Feb 7, 2021
This issue was a major obstacle for me when I migrated from PS5 to PS7.
I hope it will be addressed as soon as possible.
Fix Windows CI build, add Node.js v15
Fix Windows CI build, add Node.js v15
Fix Windows CI build, add Node.js v15