client cert based authentication for a URL

This topic contains 2 replies, has 3 voices, and was last updated by  Joakim 4 years, 1 month ago.

  • Author
  • #13314



    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.

  • #15379

    Don Jones

    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.

  • #15443


    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.

You must be logged in to reply to this topic.