gpt4 book ai didi

python - Powershell:Webclient 无法上传字符串

转载 作者:太空宇宙 更新时间:2023-11-04 06:03:23 25 4
gpt4 key购买 nike

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

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

它可以向网络服务器发送任何字符串。现在,我想在 Windows 上使用 powershell 进行相同的操作。我做了以下事情:

$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

我是否遗漏了什么?任何帮助将不胜感激。

提前致谢!

乔伊

最佳答案

您尝试过 Invoke-RestMethod 吗?

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

关于python - Powershell:Webclient 无法上传字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23483287/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com