cURL
を使用してdropbox
REST API
を呼び出しています。ここで私はやっているものです:PHP cURLのコンテンツタイプが設定されていません
$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
returnes:
> 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.
追加情報:ここでは
コンテンツタイプがerror
でnull
を示しています私は電話をしながらapplication/json
に設定しています。私は何が欠けていますか?それをどうやって得るの?
適切なカールエラーを取得するには、 'die( '
curl execの間にエラーが発生しました。Additioanl info:'。curl_error($ curl));' – DarkBee
'curl_error($ curl) "curl_close($ curl)' – Reversal
大丈夫、これを実行しました。これはエラーです。 "curl_error():2は、21行目のD:\ xampp \ htdocs \ centrify \ index.phpの有効なcURLハンドルリソースではありません" – Saani