当我尝试向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);
答案 0 :(得分:0)
使用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);