Recognize Text REST端点在成功时不返回任何结果

问题描述 投票:0回答:1

我正在使用在我的开发机器上本地运行的javascript中的ognizeText REST端点。我可以成功调用端点,获取结果的操作位置网址,然后向该网址发送GET请求。

问题是操作位置URL返回的成功是200(这意味着操作已完成并且不需要更多时间,但是结果的正文始终为空。)>

如何从响应中提取文本?

我的代码:

    var subscriptionKey: string = "my key";
    var endpoint: string = "https://eastus.api.cognitive.microsoft.com/";

    var uriBase: string = endpoint + "/vision/v2.0/recognizeText?mode=Printed";

    const fetchData = {
      headers: {
        "Content-Type": "application/json",
        "Ocp-Apim-Subscription-Key": subscriptionKey
      },
      body:
        '{"url": "https://www.bing.com/th/id/OIP.nZoyhANat4WNndv0jeoXFAHaLp?w=183&h=289&c=7&o=5&dpr=1.5&pid=1.7"}',
      method: "POST"
    };

    fetch(uriBase, fetchData).then(data => {
      var operationLocation = data.headers.get("Operation-Location");

      if (operationLocation) {
        const resultFetchData = {
          headers: {
            "Content-Type": "application/json",
            "Ocp-Apim-Subscription-Key": subscriptionKey
          },
          method: "GET"
        };

        setTimeout(function(operationLocation, resultFetchData) {
          fetch(operationLocation, resultFetchData).then(resultData => {
            alert(JSON.stringify(resultData, null, 2));
          });
        }, 10000);
      }
    });
  }

我正在使用在我的开发机器上本地运行的javascript中的ognizeText REST端点。我可以成功调用端点,获取结果的操作位置网址并发送GET请求...

microsoft-cognitive
1个回答
0
投票

您的提取请求代码块有问题,请尝试此:

© www.soinside.com 2019 - 2024. All rights reserved.