Powershell 中的 IBM Watson 视觉识别

IBM Watson Visual Recognition in Powershell

我正在尝试将 Watson Visual Recognition 集成到一个 powershell 脚本中,我已经设置了我的免费帐户并且一切都在 docker 容器中的 curl 中运行。但是我一辈子都弄不明白如何让它在 Powershell 中工作。

示例 curl 命令是

curl "https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classify?api_key={api-key}&url=https://watson-developer-cloud.github.io/doc-tutorial-downloads/visual-recognition/fruitbowl.jpg&version=2016-05-20"

其中 {api-key} 替换为实际的 api 密钥

因为这只是一个 URL 我希望我应该能够使用

Invoke-RestMethod -Uri "https://gateway-a.watsonplatform.net/visual-recognition/api/v3/classify?api_key={api-key}&url=https://watson-developer-cloud.github.io/doc-tutorial-downloads/visual-recognition/fruitbowl.jpg&version=2016-05-20"

不过Invoke-RestMethodreturns

Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send.
At line:1 char:1
+ Invoke-RestMethod -Uri "https://gateway-a.watsonplatform.net/visual-r ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

我的 Invoke-RestMethod 命令中缺少什么?我需要指定某种 headers 还是什么?

文档 link https://www.ibm.com/watson/developercloud/visual-recognition/api/v3/curl.html?curl#data-collection

默认情况下,PowerShell 在您使用 Invoke-WebRequest/RestMethod 时使用 TLS 1.0,这可能就是您无法建立安全连接的原因。因此,该站点不支持 TLS 1.0。

尝试将以下内容添加到脚本顶部以强制执行 TLS 1.2。

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12