Could we use [drupal_http_request()](https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_http_request/7) here to simpify things a bit?