client cert based authentication for a URL

Welcome Forums General PowerShell Q&A client cert based authentication for a URL

This topic contains 2 replies, has 3 voices, and was last updated by

4 years, 8 months ago.

  • Author
  • #13314

    Points: 0
    Rank: Member


    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

    Points: 1,785
    Helping HandTeam Member
    Rank: Community Hero

    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

    Points: 21
    Rank: Member

    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.

The topic ‘client cert based authentication for a URL’ is closed to new replies.