PowerShell: System.Net.Http.HttpClient always fails on first attempted connection
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
This is a re-report of Issue #19486, which was resolved for inactivity but still persists in 7.4.0. I have golfed the problem down to the following minimum code example.
> PS> $client = New-Object -TypeName System.Net.Http.HttpClient
> PS> $r1=$client.GetStringAsync('http://www.google.com')
> PS> $r1.Status
> Faulted
> PS> $r1.Exception.InnerException.InnerException.Message
> Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host..
> PS> $r1.Exception.InnerException.InnerException.InnerException | Select SocketErrorCode,ErrorCode
> SocketErrorCode ErrorCode
> ConnectionReset 10054
> PS> $r2=$client.GetStringAsync('http://www.google.com')
> PS> $r2.Status
> RanToCompletion
Expected behavior
Should connect the first time.
Actual behavior
Always fails on the first attempt to connect to a site.
Error details
No output.
Environment data
Name Value
---- -----
PSVersion 7.4.0
PSEdition Core
GitCommitId 7.4.0
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
No response
About this issue
- Original URL
- State: closed
- Created 7 months ago
- Comments: 19 (4 by maintainers)
Alas that doesn’t really help PowerShell based on .NET Core and just adds 3 additional layers of confusion.
I suggest download the .NET SDK 8.0 on Windows and demonstrate the problem on Windows side by side with it working in PowerShell 5.1.
You say it stopped working on PowerShell 7.2, that used .NET SDK 6.0
Are you also able to demonstrate it on Windows using curl with full tracing on? ( and I do mean real curl.exe, not the PowerShell 5 alias)