【发布时间】:2020-06-20 05:24:46
【问题描述】:
我正在尝试使用带有 Powershell 的 Azure 认知服务 API 来“读取”blob 存储中 .jpg 的内容。我尝试做的所有事情都使用 Azure API 演示/测试页面完美运行,所以我相当确定这在一定程度上证明了我在代码中使用的某些元素是有效的。好吧,至少在使用 API 测试工具时是这样。
这是我的 Powershell:
Clear-Host
$myUri = "<ENDPOINT value from "keys and endpoint blade">/vision/v3.0/read/analyze?language=en"
$imagePath = "<path to image in blob. accessible online and anonymously>"
$subKey = "<KEY #1 from "keys and endpoint" blade>"
$headersHash = @{}
$headersHash.Add( "Host", "westeurope.api.cognitive.microsoft.com" )
$headersHash.Add( "Ocp-Apim-Subscription-Key", $subKey )
$headersHash.Add( "Content-Type","application/json" )
$bodyHash = @{ "url" = $imagePath }
out-host -InputObject "Sending request:"
$response = Invoke-WebRequest -uri $myUri `
-Method Post `
-Headers $headersHash `
-Body $bodyHash `
-verbose
"Response: $response"
当我发送它时,我得到的只是一个:
Invoke-WebRequest : The remote server returned an error: (400) Bad Request.
At C:\scratch\testy.ps1:15 char:13
+ $response = Invoke-WebRequest -uri $myUri `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-W
ebRequest], WebException
+ FullyQualifiedErrorId :
WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
我一定缺少一些基本的东西,但我看不出是什么。没有已发布的使用 Powershell 访问我可以找到的 CS API 的示例,但是有一个 Python 示例(请求),我很确定我正在模拟并正确表示 Python 示例中的内容。但是话又说回来,它不起作用,所以有些事情是不对的。
奇怪的是,当我尝试在 Postman 中重新创建它时,我得到一个 202 但没有响应正文,因此我无法查看或提取 apim-request-id 以制造下一个检索结果的请求.
【问题讨论】:
-
请不要将答案作为问题的一部分发布。而且绝对不要发布非答案作为答案。我已经纠正了这里的问题。以后请遵循这个模式。 Stack Overflow 不是讨论论坛。如果您还没有,请拨打tour。
-
抱歉,科迪。已经看过这次旅行,现在就得到它。感谢修复。
标签: azure powershell azure-cognitive-services