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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大