Microsoft Vision API中收到JSON错误

时间:2017-03-03 11:50:57

标签: json windows api vision

我创建了一个php文件,用于测试Microsoft提供的模板中的Micrsoft Vision API https://www.microsoft.com/cognitive-services/en-us/Computer-Vision-API/documentation/QuickStarts/PHP
但是,当https://westus.dev.cognitive.microsoft.com/docs/services/56f91f2d778daf23d8ec6739/operations/56f91f2e778daf14a499e1fa/console

中的相同输入有效时,我一直收到有关JSON的错误
<?php
//Link HTTP_Request2
ini_set("include_path", '/home/peter/php:' . ini_get("include_path") );

// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
require_once 'HTTP/Request2.php';

$request = new Http_Request2('https://westus.api.cognitive.microsoft.com/vision/v1.0/analyze');
$url = $request->getUrl();

$headers = array(
    // Request headers
    'Content-Type' => 'application/json',
    'Ocp-Apim-Subscription-Key' => '****',
);

$request->setHeader($headers);

$parameters = array(
    // Request parameters
    'visualFeatures' => 'Categories',
    'language' => 'en',
);

$url->setQueryVariables($parameters);

$request->setMethod(HTTP_Request2::METHOD_POST);

// Request body
$request-> setBody("*****");

try
{
    $response = $request->send();
    echo $response->getBody();
}
catch (HttpException $ex)
{
    echo $ex;
}

?>

但是显示了此错误。 我想知道如何解决有关JSON的错误?

{"code":"BadArgument","requestId":"*****","message":"JSON format error."}

我不确定是什么类型的JSON错误,有人可以帮助找出问题,非常感谢。

0 个答案:

没有答案