dtwxmn8741 2015-07-23 21:39
浏览 62

使用CURL通过PHP进行Autodesk API调用时出错

I am trying to make call to Autodesk Authentication API through PHP with the help of CURL but I am continously getting false response. Not sure what is wrong, can anyone please suggest how to call REST services with the help of CURL in PHP?

My code is like this -

$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 is -

{"result":false}

I checked the information with curl_getinfo and it is 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 its showing "protocol.http.BadFormData" error.
  • 写回答

2条回答 默认 最新

  • dqkyz02602 2015-07-23 21:50
    关注

    Try adding:

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    

    This tells curl to return the transfer as a string of the return value of curl_exec() instead of outputting it out directly. You can read more about curl options here.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?