1

When connected on Wifi:

PS C:\Users\Julio> Invoke-RestMethod juliobs.com
Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a receive.
At line:1 char:1
+ Invoke-RestMethod juliobs.com
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
   eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

When connected on Cable:

PS C:\Users\Julio> Invoke-RestMethod juliobs.com
<!DOCTYPE html>
<!-- Last Published: April 6, 2023 --><html lang="en" >

<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />

...

Both connections are to the same router using the same DNS config. curl from cmd.exe or WSL work fine on wifi.

The same error happened in one other Wifi network.

Tested with PowerShell 5.1 (on Windows Terminal 1.16 and Windows PowerShell ISE)

PS C:\Users\Julio> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      22621  963

The error "The underlying connection was closed" is usually related to TLS, but this does not seem to be the case here.

Julio Batista Silva
  • 1,861
  • 19
  • 19
  • TLS when fails is a timeout error message which indicates the connection did not complete. I've seen similar errors when the the Wifi was using IPV6 and local was using IPV4. I would try to bypass the proxy. See : https://stackoverflow.com/questions/53463380/powershell-v5-1-invoke-restmethod-and-bypass-proxy?force_isolation=true – jdweng May 08 '23 at 17:13

0 Answers0