Powershell:Webclient无法上传字符串

时间:2014-05-05 22:56:21

标签: python powershell curl

我的https POST请求使用以下命令在UNIX上使用curl工作:

p=subprocess.Popen(['curl','-s','-k','-X','POST', '-H','Content-Type: application/json','-d',message,<https link>],stdout=subprocess.PIPE)

它可以将任何字符串发送到Web服务器。现在,我想在使用PowerShell的Windows上使用相同的功能。我做了以下事情:

$webclient = new-object system.net.webclient;
$webclient.UploadString("https://host/message","string in json format");

然而,它失败了:

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

我有遗失吗?任何帮助将不胜感激。

提前致谢!

1 个答案:

答案 0 :(得分:1)

您是否尝试过Invoke-RestMethod?

Invoke-RestMethod -Uri "https://host/message" -Method Post -ContentType "application/json" -Body '{"string in json format"}'