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

Solved
MerakiIT
Comes here often

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

HI All, 

 

my first time here, hello everyone 🙂 

 

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 🙂 

 

thank you in advance,

 

Dan 

1 Accepted Solution
AlexG
Getting noticed

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.

View solution in original post

5 Replies 5
Adam
Kind of a big deal

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.
AlexG
Getting noticed

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.

PhilipDAth
Kind of a big deal
Kind of a big deal

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.

AlexG
Getting noticed

@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.

MerakiIT
Comes here often

thank you everyone. seems the issues with tls thanks community 🙂 

Get notified when there are additional replies to this discussion.