dsag14654 2015-08-11 13:23
浏览 27

来自rest api的curl响应 - 删除标题[PHP]

I am using PHP Curl lib to make some REST API request. My code looks like:

// set up the curl resource
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $host."/oauth/token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/x-www-form-urlencoded',                                                                                
    'Authorization: Basic '.$token.''          
));       

// execute the request

$output = curl_exec($ch);

// output the authorization information - includes the header

 echo($output) . PHP_EOL;

And response looks like:

HTTP/1.1 200 OK Server: Apache-Coyote/1.1 X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 X-Frame-Options: DENY Access-Control-Allow-Origin: * Access-Control-Allow-Credentials: true Cache-Control: no-store Pragma: no-cache Content-Type: application/json;charset=UTF-8 Content-Length: 498 Date: Tue, 11 Aug 2015 10:38:25 GMT {"access_token":"access_token_here","token_type":"bearer","expires_in":43199,"scope":"read write","jti":"jti_code_here"} 

only thing I need from here is access_token, how ever I try to edit my $output only way I know to get to access token is to substr some chars, is there a way how remove headers and use rest of the response as array or json or something which i can access easy?

Thanks for any advise.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 搭建pt1000三线制高精度测温电路
    • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
    • ¥15 画两个图 python或R
    • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
    • ¥15 八路抢答器设计出现故障
    • ¥15 opencv 无法读取视频
    • ¥15 按键修改电子时钟,C51单片机
    • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
    • ¥20 5037端口被adb自己占了
    • ¥15 python:excel数据写入多个对应word文档