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