perlnewbie9292
Programmer
Hello all,
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 the POST request, for authentication.
What is the best way or way to accomplish this? I've found plenty of example to be able to perform this task in .net/C# but I am not finding anything that will accomplish this task in PowerShell.
Here is my POST request code, again I would like to point to a cert stored locally "C:\code\cert.crt" and pass it during the web transaction.
Thanks for all the help in advanced.
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 the POST request, for authentication.
What is the best way or way to accomplish this? I've found plenty of example to be able to perform this task in .net/C# but I am not finding anything that will accomplish this task in PowerShell.
Here is my POST request code, again I would like to point to a cert stored locally "C:\code\cert.crt" and pass it during the web transaction.
Code:
$url = "[URL unfurl="true"]https://myUrl/uploadTester"[/URL]
$data = '{"data": "988309487577839444"}'
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$b = [System.Text.Encoding]::ASCII.GetBytes($data)
$web = [System.Net.WebRequest]::Create($url)
$web.Method = "POST"
$web.ContentLength = $b.Length
$web.ContentType = "application/x-[URL unfurl="true"]www-form-urlencoded"[/URL]
$stream = $web.GetRequestStream()
$stream.Write($b,0,$b.Length)
$stream.close()
$reader = New-Object System.IO.Streamreader -ArgumentList $web.GetResponse().GetResponseStream()
$reader.ReadToEnd()
$reader.Close()
Thanks for all the help in advanced.