Powershell Invoke-Restmethod 由于 SSL/TLS 安全通道(Smartsheets API)而中止

Powershell Invoke-Restmethod aborted due to SSL/TLS Secure Channel (Smartsheets API)

我在使用 powershell Invoke-Restmethod cmdlet 调用智能表 api 时遇到问题。 附加的脚本以前工作过。请参阅下面有关 SSL/TLS 的错误消息。

$apiKey = "**********"
$url = "https://api.smartsheet.com/2.0/sheets"
$get_headers = @{"Authorization" = "Bearer " + $apiKey}
$put_headers = @{}
$put_headers.Add("Authorization", "Bearer " + $apiKey)
$put_headers.Add("Content-Type", "application/json")

$response = Invoke-RestMethod -Uri $url -Headers $get_headers

Invoke-RestMethod : The request was aborted: Could not create SSL/TLS secure 
channel.

这个错误到底有没有?

Smartsheet API 放弃了对 TLS 1.0 的支持,这是 Powershell 的默认设置。

上面的有一些很好的解决办法。基本上,您需要告诉 Powershell 在调用时使用 TLS 1.2。