Author Posts

February 24, 2014 at 1:15 pm


we want to check URL response of a .asmx URL which needs a client certificate for authenticating.
I got the cert object and then passed it to invoke-webrequest cmdlet, but no matter what i try I always get this error
"The underlying connection was closed".


$WebClient = New-Object System.Net.WebClient
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}


$cert=(Get-ChildItem cert: -Recurse | where {$_.Thumbprint -eq "abcdefgh3333.....something"}| Select -First 1)

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
#load my client certificate defined by thumbprint

$HTTP_Request = [System.Net.WebRequest]::Create($url)
$HTTP_Request.ClientCertificates.Add($cert )
# We then get a response from the site.
$HTTP_Response = $HTTP_Request.GetResponse()

Can someone please help me.

May 19, 2014 at 11:06 am

Unfortunately, the best place to troubleshoot this is probably on the web server, using its logs, and possibly writing a test Web page that can provide more information on what the server is receiving. It's impossible to tell, just from looking at your script, what might be wrong.

May 21, 2014 at 2:25 am

I would recommend you to install Fiddler. It is probably the quickest way to see what is going on. And it will help you determine if the error is with a local certificate or on the server side.