Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

System.Net.WebRequest not presenting my certificate

$
0
0

Below is a snippet of code I have written to make a SOAP request to an internal Web Service we have.  If I run this with Fiddler running Fiddler alerts that the site is requesting a cert.  If I provide the cert to Fiddler this runs perfectly.  If I turn off Fidler then I get an error that the connection was closed.  I am beating my head against the wall because I am adding the cert to the ClientCertificates collection, and when I debug it I can see that it has it.  Any ideas why it is not presenting it at run time?  (you will see where I have tested with grabbing it from the local machine store and creating it from the file, and neither option is working)

$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]::CreateFromCertFile($certPath)
#$cert = get-item cert:\LocalMachine\* | get-ChildItem | Where-Object -FilterScript {($_.FriendlyName -eq "HRSYS")}
$soapWebRequest = [System.Net.WebRequest]::Create($url)
$soapWebRequest.ClientCertificates.Add($cert)
$soapWebRequest.Headers.Add("SOAPAction", $serviceAddress")
$soapWebRequest.ContentType = "text/xml;charset=`"utf-8`""
$soapWebRequest.Accept = "text/xml"
$soapWebRequest.Method = "POST"
$soapWebRequest.Timeout = 60000
$soapWebRequest.UseDefaultCredentials = $true


Viewing all articles
Browse latest Browse all 2562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>