我正在尝试开始使用计算机视觉API,但我一直得到一个空的回应。我在php中的请求(由Postman导出)看起来像这样:
<?php
$request = new HttpRequest();
$request->setUrl('https://westcentralus.api.cognitive.microsoft.com/vision/v1.0/recognizeText');
$request->setMethod(HTTP_METH_POST);
$request->setQueryData(array(
'language' => 'en',
'handwriting' => 'true'
));
$request->setHeaders(array(
'Postman-Token' => '442d04f7-49a0-4262-9d0f-666fe5240cc7',
'Cache-Control' => 'no-cache',
'Content-Type' => 'application/octet-stream',
'Ocp-Apim-Subscription-Key' => 'KEY'
));
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
以上代码适用于ocr端点!
使用Postman将文件作为二进制文件传递。
编辑:我还尝试从这里复制/粘贴代码:https://docs.microsoft.com/en-gb/azure/cognitive-services/computer-vision/quickstarts/php#ocr-php-example-request如果我将ocr端点更改为recognText,我也会得到一个空响应!
答案 0 :(得分:1)
与其他计算机视觉端点不同,RecognizeText
是一种异步操作。除非图像出现问题,否则您将获得202响应而不是通常的200响应。 202响应通常包含空响应主体。在这种特殊情况下,您可以找到可以查询任务完成情况的URL。文档是here。您要查找的标题是Operation-Location
。