respons http laravel dengan cookie
use GuzzleHttp\Client;
use GuzzleHttp\Cookie\CookieJar;
use Illuminate\Support\Facades\Http;
....
// Get the token generated when you are logged
public function getToken(){
$response = Http::withHeaders([
'login' => 'login',
'password' => 'password'
])->post('/urlOfConnection');
return $response->cookies()->getCookieByName('cookieName');
}
// Get data from api with cookie
public function getDataFromApi(){
$jwt = $this->getToken();
$cookieJar = CookieJar::fromArray([
$jwt->getName() => $jwt->getValue()
], $jwt->getDomain());
$req = new Client();
$res = $req->request('GET', '/getDataFromApi',
['cookies' => $cookieJar]);
return $res->getBody();
}
Thibaudkhan