PHP cURL内容类型未设置

时间:2016-03-29 09:06:00

标签: php api rest curl dropbox

我正在使用dropbox拨打REST API $service_url = 'https://api.dropboxapi.com/2/files/create_folder'; $curl = curl_init(); $curl_post_data = array( 'path' => '/ehsan/malik', ); curl_setopt($curl, CURLOPT_URL, $service_url); curl_setopt($curl,CURLOPT_HTTPHEADER,array('Content-Type: application/json','Authorization: Bearer ********accesstoken*********')); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($curl_post_data)); $curl_response = curl_exec($curl); if ($curl_response === false) { $info = curl_getinfo($curl); curl_close($curl); die('<br>error occured during curl exec. Additioanl info: ' . var_export($info)); } curl_close($curl); $decoded = json_decode($curl_response); if (isset($decoded->response->status) && $decoded->response->status == 'ERROR') { die('error occured: ' . $decoded->response->errormessage); } echo 'response ok!'; var_export($decoded->response); 电话。这就是我在做的事情:

$info

当脚本运行时,这就是> array ( 'url' => 'https://api.dropboxapi.com/2/files/create_folder', > 'content_type' => NULL, 'http_code' => 0, 'header_size' => 0, > 'request_size' => 0, 'filetime' => -1, 'ssl_verify_result' => 1, > 'redirect_count' => 0, 'total_time' => > 0.717000000000000081712414612411521375179290771484375, 'namelookup_time' => > 0.12399999999999999911182158029987476766109466552734375, 'connect_time' => > 0.4210000000000000408562073062057606875896453857421875, 'pretransfer_time' => 0, 'size_upload' => 0, 'size_download' => 0, > 'speed_download' => 0, 'speed_upload' => 0, 'download_content_length' > => -1, 'upload_content_length' => -1, 'starttransfer_time' => 0, 'redirect_time' => 0, 'redirect_url' => '', 'primary_ip' => > '108.160.172.205', 'certinfo' => array ( ), 'primary_port' => 443, > 'local_ip' => '192.168.1.234', 'local_port' => 9306, ) error occured > during curl exec. 返回的内容:

null

其他信息:

此处的内容类型在error中显示为application/json,但我在拨打电话时将其设置为Comparator<>。我错过了什么?如何做到对不对?

1 个答案:

答案 0 :(得分:0)

尝试删除POST数据的JSONification:

curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);

并删除'Content-Type: application/json'标题。让cURL为您管理标题。