cURL 401 Unauthorized only on Webserver - localhost working fine

Viewed 40

I am trying to download files via cURL using a Bearer as authorization.

While this works fine on my localhost, it somehow does not work on my webserver:

$cookie_path = $plugin_tmp_path . 'session.txt';

    $ch = curl_init();

    $options = array(
        CURLOPT_URL => $file,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HEADER => false,
        CURLOPT_HTTPHEADER => array(
            "Content-Type: image/jpeg",
            "Accept: application/json",
            "Authorization: Bearer " . $_SESSION['fm-data-api-token'],
            "Cookie: fm-data-api-token=" . $_SESSION['fm-data-api-token'],
        ),
        CURLOPT_COOKIEJAR => $cookie_path,
        CURLOPT_COOKIEFILE => $cookie_path,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_ENCODING => "",
        CURLOPT_AUTOREFERER => true,
        CURLOPT_CONNECTTIMEOUT => 120,
        CURLOPT_TIMEOUT => 120,
        CURLOPT_MAXREDIRS => 10
    );

    curl_setopt_array($ch, $options);
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

The cookie is being written, so this should not be the problem.

Any ideas?

0 Answers
Related