I have a custom module which is moderating content before entry save, I am looking to use a Microsoft Azure API to handle the moderation, in their documentation they use a HTTP library to make the request.
Is there something which Yii or Craft already offers which I could utilise, if so, how would I perform the same function which is below.
The example provided by MS Azure is below. {body}
would be content which I pass in.
<?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://westus.api.cognitive.microsoft.com/contentmoderator/moderate/v1.0/ProcessText/Screen');
$url = $request->getUrl();
$headers = array(
// Request headers
'Content-Type' => 'text/plain',
'Ocp-Apim-Subscription-Key' => '{subscription key}',
);
$request->setHeader($headers);
$parameters = array(
// Request parameters
'autocorrect' => '{boolean}',
'PII' => '{boolean}',
'listId' => '{string}',
'classify' => 'True',
'language' => '{string}',
);
$url->setQueryVariables($parameters);
$request->setMethod(HTTP_Request2::METHOD_POST);
// Request body
$request->setBody("{body}");
try
{
$response = $request->send();
echo $response->getBody();
}
catch (HttpException $ex)
{
echo $ex;
}
Thanks