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.