【问题标题】:Bad HTTP "Content-Type" header from the Dropbox API来自 Dropbox API 的错误 HTTP“Content-Type”标头
【发布时间】:2015-11-10 06:08:08
【问题描述】:

当我尝试向 Dropbox API (v2) 发出简单的 curl 请求时,我收到此错误:

Error in call to API function "users/get_current_account": Bad HTTP "Content-Type" header: "application/x-www-form-urlencoded". Expecting one of "application/json", "application/json; charset=utf-8", "text/plain; charset=dropbox-cors-hack".

PHP 代码:

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_POST, true);       
curl_setopt($ch, CURLOPT_URL, "https://api.dropboxapi.com/2/users/get_current_account" );
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer " . $accessToken) );
echo curl_exec($ch);
curl_close($ch);     

【问题讨论】:

    标签: php dropbox-api


    【解决方案1】:

    使用CURLOPT_POST 选项指定内容类型(到application/x-www-form-urlencoded,基于the documentation)。可以改为使用 CURLOPT_CUSTOMREQUEST 选项将其设为 POST 请求。

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_URL, "https://api.dropboxapi.com/2/users/get_current_account" );
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer " . $accessToken) );
    echo curl_exec($ch);
    curl_close($ch);     
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-17
      • 1970-01-01
      • 2022-06-25
      • 2014-03-01
      • 2013-12-21
      相关资源
      最近更新 更多