我正在尝试向API发出两个请求。
我第一次请求获取Api令牌,我等待获取令牌响应,然后提出第二个请求。
$result = $token->post($uriToken, [
'form_params' => [
'grant_type' => 'client_credentials',
'client_id' => '25',
'client_secret' => 'l6gLGd4SXuOCnYgUNDqkIMXL9djaEVZLqTqevM8U',
'scope' => '*'
]
]);
$tokenResult = json_decode($result->getBody()->getContents())->access_token;
if($tokenResult){
$cli = new Client([
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer ' . $tokenResult,
'Content-Type' => 'application/json',
]
]);
$post = $cli->requestAsync('POST', $uriClient,
[
'json' =>
[
'dni' => $dni,
'target' => $target
]
])->wait();
}
with this code, I always get 400 error.
When I made the first request in Postman and copy in code, it sometimes works and other get 400 error Bad Request