【问题标题】:Azure Cognitive Services REST API URL returns 404 error in postmanAzure 认知服务 REST API URL 在邮递员中返回 404 错误
【发布时间】:2021-07-27 09:23:17
【问题描述】:

在邮递员中访问以下 URL 时遇到问题(出现 404 错误)

https://australiaeast.api.cognitive.microsoft.com/formrecognizer/v2.1/prebuilt/invoice/analyze

该 URL 取自 Microsoft 自己的参考指南,我可以在他们的网站上对其进行测试: https://australiaeast.dev.cognitive.microsoft.com/docs/services/form-recognizer-api-v2-1/operations/5ed8c9843c2794cbb1a96291

任何帮助将不胜感激。

【问题讨论】:

  • 你能添加更多关于你的实施的细节吗?至少显示您的邮递员要求,以便我们确保您做正确的事情
  • 嗨 - 我最终通过向邮递员添加一些缺少的标题解决了这个问题。谢谢@NicolasR

标签: rest postman azure-cognitive-services


【解决方案1】:

为了帮助可能遇到此问题的其他人,在 POST /invoice/analyze 期间需要两个标头为described in the API reference

  1. Ocp-Apim-Subscription-Key - 将“表单识别器”资源添加到您的订阅后,可以在 Azure 门户中找到此信息
  2. Content-Type - 这取决于您打算如何过帐发票。

这是我在 Powershell 中尝试过的示例

$myApiKey = "<Your key from Azure Portal>";
$myEndpoint = "<Your endpoint from Azure Portal>";

# Post the invoice image/pdf that you want cognitive services to analyze
$resp1 = Invoke-WebRequest `
  -Method Post `
  -Uri "$myEndpoint/formrecognizer/v2.1/prebuilt/invoice/analyze" `
  -Headers @{ "Ocp-Apim-Subscription-Key" = $myApiKey; "Content-Type" = "application/json" } `
  -Body "{ 'source' : 'https://github.com/Azure/azure-sdk-for-net/raw/main/sdk/formrecognizer/Azure.AI.FormRecognizer/tests/samples/trainingFiles/Form_2.jpg' }" `

# Response header contains a url to get status and results of the operation
$opUrl = $resp1.Headers.'Operation-Location'

# Form recognizer may take a few seconds to complete analysis.  Loop and sleep for it to complete.
$status = "";
$resp2 = {};
Do
{
  $resp2 = Invoke-WebRequest `
    -Method Get `
    -Uri $opUrl `
    -Headers @{ "Ocp-Apim-Subscription-Key" = $myApiKey };

  $extractedInvoice = $resp2.Content | ConvertFrom-Json;

  $status = $extractedInvoice.status;
  if (($status -eq "running") -or ($status -eq "notStarted")) {
    Write-Host("Waiting for operation to comlete.  Sleeping for 10 seconds...");
    Start-Sleep -Seconds 10;
  }
} While(($status -eq "running") -or ($status -eq "notStarted"));

$resp2.Content;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-01
    • 2020-08-02
    • 2018-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-24
    • 1970-01-01
    相关资源
    最近更新 更多