Я пытаюсь сделать два запроса к 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