I have a similar question realted to this post
An Unexpected error occured on a send
My issue is slightly different where I'm actually getting a response back from the server on a windows server 2012 R2, but my local machine I'm getting
The underlying connection was closed: An unexpected error occurred on a send.
I understand that the server is ending the connection or the timeout is too low is the prescribed reason via Microsoft. This is the same script on 2 different machines one working, one not. My local machine is what is the error-thrower.
Obviously this is not a direct issue with my script rather my localhost so I'm hoping someone could provide some insight as to why this works on a server host and not my laptop on the same domain?
If I use the try/catch on my local, all I see is this error. If I remove the try catch, I get the full response
Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
At C:\blah some directory Examples\blah\myscript.ps1:82 char:17
+ $response = Invoke-WebRequest -Headers $headers -Method GET -ContentType "ap ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
id: 67kjadsfj5029838k3ka70387fe400
state: active
[I get a response]
So I'm actually getting a response back from the host with the requested data so I have to take the invokation out of the try/catch on my local to get it. Obviously not ideal, I'd prefer to keep the script in-tact
Ultimately, I am hoping if someone could provide some insight as to why powershell on my local machine is throwing this error and yet giving me the response, how do I suppress or fix it? If I could get the why and how that would be great but I'd settle for how at this point.