进程休息响应php

我打电话给一个站点获取访问令牌。这是响应如何使用php获取实际的令牌。进程休息响应php

HTTP/1.1 200 OK Date: Sat, 16 Dec 2017 16:54:20 GMT 

Content-Type: application/json;

charset=UTF-8

Content-Length: 113

Connection: keep-alive

Cache-Control: no-store

Server: Apigee Router { "access_token": "1NQA27eHVzHC6idx2f7JDbJiD4CQ", "expires_in": "3599" }

以下代码失败。

curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Basic '.$credentials)); //setting a custom header 

curl_setopt($curl, CURLOPT_HEADER, true);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$curl_response = curl_exec($curl);

$token = $curl_response['access_token'];

echo "<br/>";

echo $token;

回答:

您需要在访问值之前解码JSON。

$curl_response = curl_exec($curl); 

curl_close ($curl);

$data = json_decode($curl_response,true);

$token = $data['access_token'];

echo "<br/>";

echo $token;

以上是 进程休息响应php 的全部内容, 来源链接: utcz.com/qa/261257.html

回到顶部