Reputation: 541
My https POST request works using curl on UNIX with python using the following command:
p=subprocess.Popen(['curl','-s','-k','-X','POST', '-H','Content-Type: application/json','-d',message,<https link>],stdout=subprocess.PIPE)
It can send any string to the web server. Now, I would like have the same on Windows using powershell. I have done the following:
$webclient = new-object system.net.webclient;
$webclient.UploadString("https://host/message","string in json format");
However, it failed:
Exception calling "UploadString" with "2" argument(s): "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."
At line:1 char:24
+ $webclient.UploadString <<<< ("https://host/message","strng in json format");
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Is there somethign am I missing? Any help would be greatly appreciated.
Thanks in advance!
Joie
Upvotes: 2
Views: 1299
Reputation: 1114
Have you tried Invoke-RestMethod?
Invoke-RestMethod -Uri "https://host/message" -Method Post -ContentType "application/json" -Body '{"string in json format"}'
Upvotes: 1