What is the best way to handle HTTP requests within a plugin using Yii or Craft? 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.
&lt;?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-&gt;getUrl();

$headers = array(
    // Request headers
    'Content-Type' =&gt; 'text/plain',
    'Ocp-Apim-Subscription-Key' =&gt; '{subscription key}',
);

$request-&gt;setHeader($headers);

$parameters = array(
    // Request parameters
    'autocorrect' =&gt; '{boolean}',
    'PII' =&gt; '{boolean}',
    'listId' =&gt; '{string}',
    'classify' =&gt; 'True',
    'language' =&gt; '{string}',
);

$url-&gt;setQueryVariables($parameters);

$request-&gt;setMethod(HTTP_Request2::METHOD_POST);

// Request body
$request-&gt;setBody(&quot;{body}&quot;);

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

Thanks
Craft includes Guzzle which is very full-featured... I'd use that.
Sorry I don't have time for converting your example but here's a simplified version of how to use it in a Craft plugin:
$client = new \GuzzleHttp\Client([
    'base_uri' =&gt; 'https://www.example.com/api',
    'http_errors' =&gt; false,
    'timeout' =&gt; 10
]);

$data = ['some' =&gt; 'stuff'];
$uri = 'post-a-thing'

$response = $client-&gt;request(
    'POST',
    $uri, [
        'body' =&gt; json_encode($data),
        'headers' =&gt; [
            'User-Agent' =&gt; 'CraftCMS',
            'Content-type' =&gt; 'application/json'
        ]
    ]
);

(I usually set http_errors to false so that I can handle http error responses in my own code and fail more gracefully than Guzzle).