Powershell http post with .cer for auth

前端 未结 1 1942
再見小時候
再見小時候 2021-01-23 15:03

Pretty new to PowerShell and hoping someone can point me in the right direction.

I need to perform a POST request and have to pass it a locally stored cert (x509) during

相关标签:
1条回答
  • 2021-01-23 15:25

    It's pretty easy to convert C# to PowerShell. Give this a try:

    [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
    $cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]::CreateFromCertFile("C:\Users\Andy\Desktop\Test.cer")
    $web = [System.Net.WebRequest]::Create($url)
    $web.ClientCertificates.Add($Cert)
    

    I adapted this from: http://support.microsoft.com/kb/895971

    Looks like the key is the ClientCertificates property.

    http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.clientcertificates.aspx

    0 讨论(0)
提交回复
热议问题