2017-08-12 7 views
0

私はAzure OCRサービスを使ってイメージのテキストを元に戻そうとしています。 は、残念ながら、私はいつもこのエラーを取得しています:Azure認知サービスのPHP "Json Format Error"

{"code":"BadArgument","requestId":"49cecd3b-7be3-4aaa-9a5e-fXXXXXXXXXXX","message":"JSON format error."}

私のコードは次のとおりです。

<?php 

(http://hc.apache.org/httpcomponents-client-ga/) 
require_once 'HTTP/Request2.php'; 

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

$headers = array(

    'Content-Type' => 'application/json', 

    'Ocp-Apim-Subscription-Key' => 'c7b9e7ab25b14XXXXXXXXXXXXXXXXXX', 
); 


$request->setHeader($headers); 

$parameters = array(

    'language' => 'unk', 
    'detectOrientation ' => 'true', 
); 

$url->setQueryVariables($parameters); 

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


$request->setBody("https://image.spreadshirtmedia.net/image-server/v1/mp/compositions/P116103877MPC131734766/views/1,width=300,height=300,appearanceId=1,backgroundColor=E8E8E8,version=1472099537/hallo-sprechblase-auf-babybauch-oder-babyshirt-t-shirts-maenner-premium-t-shirt.jpg"); 

try 
{ 
    $response = $request->send(); 
    echo $response->getBody(); 

} 
catch (HttpException $ex) 
{ 
    echo "Fehler :("; 
    echo $ex; 
} 
?> 

答えて

0

あなたは体のような画像URLを指定しているが、それは誤りとしてJSONとしてエンコードする必要がありますメッセージに示されます。試してください:

$body = array('url' => 'https://image.spreadshirtmedia.net/image-server/v1/mp/compositions/P116103877MPC131734766/views/1,width=300,height=300,appearanceId=1,backgroundColor=E8E8E8,version=1472099537/hallo-sprechblase-auf-babybauch-oder-babyshirt-t-shirts-maenner-premium-t-shirt.jpg'); 

$request->setBody(json_encode($body)); 
関連する問題