You are here

private function BackupMigrateDropboxAPI::sendHttpRequest in Backup and Migrate Dropbox 7.2

Executes a curl request.

Parameters

string $url:

array $headers:

string $body:

Return value

string The response.

Throws

\RuntimeException On any error at the curl level, an exception will be thrown.

1 call to BackupMigrateDropboxAPI::sendHttpRequest()
BackupMigrateDropboxAPI::sendMessage in ./backup_migrate_dropbox.dropbox_api.inc
Sends a request to Dropbox and returns the response.

File

./backup_migrate_dropbox.dropbox_api.inc, line 360
backup_migrate_dropbox.api.inc

Class

BackupMigrateDropboxAPI
@file backup_migrate_dropbox.api.inc

Code

private function sendHttpRequest($url, $headers, $body) {
  $options = [
    CURLOPT_URL => $url,
    CURLOPT_HTTPHEADER => $headers,
    CURLOPT_POST => TRUE,
    CURLOPT_RETURNTRANSFER => TRUE,
  ];
  if (!empty($body)) {
    $options[CURLOPT_POSTFIELDS] = $body;
  }
  $request = curl_init();
  curl_setopt_array($request, $options);
  $response = curl_exec($request);
  if ($response === FALSE) {
    $response_code = curl_getinfo($request, CURLINFO_HTTP_CODE);
    if (curl_error($request)) {
      throw new RuntimeException('Curl error: ' . curl_error($request));
    }
    elseif ($response_code >= 500) {
      throw new RuntimeException('Dropbox server error. Try later or check status.dropbox.com for outages.');
    }
    else {
      throw new RuntimeException("Error: http response code: {$response_code}");
    }
  }
  curl_close($request);
  return $response;
}