cancel
Showing results for 
Search instead for 
Did you mean: 

Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send..

SOLVED
Highlighted
Just browsing

Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send..

HI All, 

 

my first time here, hello everyone Smiley Happy 

 

i am reaching out to the community to get help on the following powershell syntax that is causing me a sight headache. i just want to get very basic information and take it from there but getting some errors. i have used snippets found from here: https://github.com/ronfowler/merakiapi 

 

code: 
$merakiAPI = "https://dashboard.meraki.com/api/v0"

$headers = @{
"X-Cisco-Meraki-API-Key" = "XXXXX"
"Content-Type" = "application/json"
}

$uriStem = "/organizations"

$uri = "$($merakiAPI)$($uriStem)"

#Write-Host "GET - $($uri)"

$response = Invoke-WebRequest -Method Get -Uri $uri -Headers $headers

 

Error: 

Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.

 

any idea what i am doing incorrectly here any help would be awesome Smiley Happy 

 

thank you in advance,

 

Dan 

1 ACCEPTED SOLUTION

Accepted Solutions
Getting noticed

Re: Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send

My scripts all started failing a week ago (ish) as well. There was a sticky post about the Meraki TLS change to the top of this board, but it didn't contain the PS fix.

 

Try adding the below code to the top of your script:

 

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

 

Once I added this, it forced the connection to use TLS 1.2 and my API calls succeeded.

5 REPLIES
Kind of a big deal

Re: Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send

I don't see anything immediately obvious.  Is it throwing a specific error?  Have you tried using Postman, it is free and helps design your queries and see responses a little more easily.  You can also export queries in different code formats like Python etc...

Adam R MS | CISSP, CISM, VCP, MCITP, CCNP, ITILv3, CMNO
If this was helpful click the Kudo button below
If my reply solved your issue, please mark it as a solution.
Getting noticed

Re: Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send

My scripts all started failing a week ago (ish) as well. There was a sticky post about the Meraki TLS change to the top of this board, but it didn't contain the PS fix.

 

Try adding the below code to the top of your script:

 

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

 

Once I added this, it forced the connection to use TLS 1.2 and my API calls succeeded.

Kind of a big deal

Re: Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send

The Powershell service doesn't support negotiating to a stronger cipher suite?  I'm amazed!!!

 

It should support upgrading to stronger crypto without needing a code change.

Getting noticed

Re: Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send

@PhilipDAth

 

You're not wrong. My preference would be to start at the strongest cipher first and iterate it's way down to the weakest. I found a blog post or two regarding ways to work the snippet I posted above into the local PS profile itself, but when you have automation servers that are changing frequently, or ones that you don't manage, it's a real pain to mess with that.

Just browsing

Re: Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send

thank you everyone. seems the issues with tls thanks community Smiley Happy