Error in Autodesk API call through PHP with CURL -
i trying make call autodesk authentication api through php of curl continously getting false response. not sure wrong, can please suggest how call rest services of curl in php?
my code -
$url = 'https://developer.api.autodesk.com/authentication/v1/authenticate'; $data = array("client_id" => $consumer_key,"client_secret" => $secret_key,"grant_type"=>$grant_type); $ch=curl_init($url); echo $ch; $data_string = json_encode($data); echo $data_string; curl_setopt($ch, curlopt_customrequest, "post"); curl_setopt($ch,curlopt_httpheader,array('content-type'=>'application/x-www- form-urlencoded')); curl_setopt($ch, curlopt_postfields, array("customer"=>$data_string)); $result = curl_exec($ch); curl_close($ch); $data_return=array("result"=> $result); echo json_encode($data_return);
output -
{"result":false}
i checked information curl_getinfo , like- array ( 'url' => 'https://developer.api.autodesk.com/authentication/v1/authenticate', 'content_type' => null, 'http_code' => 0, 'header_size' => 0, 'request_size' => 0, 'filetime' => -1, 'ssl_verify_result' => 0, 'redirect_count' => 0, 'total_time' => 0.34300000000000003, 'namelookup_time' => 0, 'connect_time' => 0.23400000000000001, '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' => '52.26.41.203', 'certinfo' => array ( ), 'primary_port' => 443, 'local_ip' => '192.168.1.106', 'local_port' => 62792, )
in reponse showing "protocol.http.badformdata" error.
try adding:
curl_setopt($ch, curlopt_returntransfer, true);
this tells curl return transfer string of return value of curl_exec() instead of outputting out directly. can read more curl options here.
Comments
Post a Comment