Powershell HTTPS REST api GET/POST

flo*_*oyd 3 .net rest powershell https

我试图测试一个非常简单的PowerShell脚本来从内部票务站点获取/发布数据.我遇到的问题似乎与所需的SSL证书有关.有人可以帮我理解我需要添加哪些代码才能使其工作?

谢谢

返回错误:使用"0"参数调用"GetResponse"的异常:"底层连接已关闭:无法为SSL/TLS安全通道建立信任关系."

现行代码:

 $url = "https://username:password@IPADDRESS/ticket"
 $command = get-content jsonfile.json

 $bytes = [System.Text.Encoding]::ASCII.GetBytes($command)
 $web = [System.Net.WebRequest]::Create($url)
 $web.Method = "POST"
 $web.ContentLength = $bytes.Length
 $web.ContentType = "application/json"
 $stream = $web.GetRequestStream()
 $stream.Write($bytes,0,$bytes.Length)
 $stream.close()

 $reader = New-Object System.IO.Streamreader -ArgumentList
 $web.GetResponse().GetResponseStream()
 $reader.ReadToEnd()
 $reader.Close()
Run Code Online (Sandbox Code Playgroud)

flo*_*oyd 5

我能够从Powershell v3中引入的新Invoke-RestMethod cmdlet中获取所需的功能.此方法允许您包含我所做的证书,但没有收到任何错误.