我正在尝试将沃森视觉识别集成到一个powershell脚本中,我已经设置了我的免费帐户,并且一切都在码头容器中工作。但我一辈子都想不出如何让它在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-RestMethod返回
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命令中遗漏了什么?我是否需要指定某种类型的标题或其他东西?
文档链接https://www.ibm.com/watson/developercloud/visual-recognition/api/v3/curl.html?curl#data-collection
发布于 2018-03-21 22:04:05
默认情况下,PowerShell在使用Invoke-WebRequest/RestMethod时使用TLS1.0,这可能是您无法建立安全连接的原因。因此,该站点不支持TLS 1.0。
尝试将下面的内容添加到脚本的顶部,以强制执行TLS 1.2。
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12https://stackoverflow.com/questions/49416747
复制相似问题