Odd issue with Invoke-RestMethod in Windows PowerShell 5.1 using the GET method

Swin 61 Reputation points
2022-10-16T19:22:32.11+00:00

Hi,

I'm seeing a really odd issue when invoking the Invoke-RestMethod CmdLet against a specific device using the GET method. The OS I am using is Windows 11 and I have confirmed this behaviour on multiple PCs.

If I use the Invoke-RestMethod with the POST method, all is fine. If I use the Invoke-RestMethod in PS 7.x, whether it be the GET or POST methods, all is fine. If I am really quick within a Win PS 5.1 session and issue a GET request straight after a POST request (thus I believe I am using the same TCP connection), all is fine....

Viewing a PCAP, we see that the issue appears to be after the Client Hello, Server Hello and the Certificate and Key Exchange info (all of which is fine), but then the server device sends a TLS message containing the Change Cipher Spec protocol and the Handshake protocol, at which point the client immediately sent a FIN ACK. The error seen in Win PS shows as:

   PS C:\Users\me> $response = Invoke-RestMethod 'https://192.168.1.1/getxml?location=/command/security/certificates/ca/show/format' -Method 'GET' -Headers $headers  
   Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send.  
   At line:1 char:13  
   + $response = Invoke-RestMethod 'https://192.168.1.1./getxml?location ...  
   +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
       + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc  
      eption  
       + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand  

If we force TLS 1.2 within Win PS 5.1, it's a little easier to see the TLS exchange and where the failure is:

250902-image.png

Looking at a PCAP for the Invoke-RestMethod request using a POST method to the same device, we see that things just continue as normal:

   $response = Invoke-RestMethod 'https://192.168.1.1/putxml' -Method 'POST' -Headers $headers -Body $body  

250921-image.png

As mentioned, the request works fine within PS 7.x and other clients (such as PostMan). It even works in PS 5.1 if issued immediately after a successfully POST request has been sent.

This feels very much like a bug, perhaps alluded to in this Stack Overflow post, albeit this was nearly a year ago!!! - https://stackoverflow.com/a/70351805/505174

If anyone has got any information on this, I would be grateful.

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Devarapu, R (Reja) 0 Reputation points
    2023-08-24T12:14:09.3233333+00:00

    Hi Swin,

    I see it has been long since you posted the above. I have same issue , by any chance did you find a solution for it?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.