When I try a simple curl request to the Dropbox API (v2), I get this error:
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".
The PHP code:
$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);
Using the CURLOPT_POST
option specifies a content type (to application/x-www-form-urlencoded
, based on the documentation ). It's possible instead to make it a POST request using the CURLOPT_CUSTOMREQUEST
option.
$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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.