Согласно FaceList - API для создания , формат тела:
{
"name": "sample_list",
"userData": "User-provided data attached to the face list."
}
Нам нужно отправить тело следующим образом, тогда оно должно работать.
// Request body
$request->setBody('{"name":"facelistName","userData":"it is optional"}'); //replace it with your name and userData
Если хотите сослаться на 'HTTP/Request2.php';
, нам нужно установить http_request2
pear install http_request2
Как установить менеджер пакетов PEAR, перейдите по этой ссылке .
Демо-код:
<?php
// 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://xxx.api.cognitive.microsoft.com/face/v1.0/facelists/{faceListId}');
$url = $request->getUrl();
$headers = array(
// Request headers
'Content-Type' => 'application/json',
'Ocp-Apim-Subscription-Key' => 'xxxxxxxxxx', //replace it with your key
);
$request->setHeader($headers);
$parameters = array(
'faceListId' => 'facelistId'
);
$url->setQueryVariables($parameters);
$request->setMethod(HTTP_Request2::METHOD_PUT);
// Request body
$request->setBody('{"name":"facelistName","userData":"it is optional"}');//replace it with your name and userData
try
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}
?>