I am try to download the nuget.exe via Invoke-WebRequest inside a function.
If i use Windows Powershell ISE everything works fine.
$request = Invoke-WebRequest -Uri "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -UseBasicParsing -verbose
VERBOSE: GET https://dist.nuget.org/win-x86-commandline/latest/nuget.exe with 0-byte payload
VERBOSE: received 7088048-byte response of content type application/x-msdownload
If i use VSCODE Powershell extension i get.
$request = Invoke-WebRequest -Uri "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -UseBasicParsing -verbose
VERBOSE: GET https://dist.nuget.org/win-x86-commandline/latest/nuget.exe with 0-byte payload
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
At line:1 char:12
+ $request = Invoke-WebRequest -Uri "https://dist.nuget.org/win-x86-com ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
I already tried
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
[System.Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13 -bor [Net.SecurityProtocolType]::Ssl3
$PSVersionTable in ISE and VSCODE extension is identical
Name Value
---- -----
PSVersion 5.1.19041.1682
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.19041.1682
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Is there a way to analyze/debug the difference? There must be some kind of difference in this environments.
Other download variants besides Invoke-WebRequest won't work for me, because i need the $request answer to phrase the header in some variants