Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel http response with cookie

use GuzzleHttpClient;
use GuzzleHttpCookieCookieJar;
use IlluminateSupportFacadesHttp;

....
  
// 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();
}
Comment

PREVIOUS NEXT
Code Example
Php :: provide difference between interface and abstract class php 
Php :: Clear Caching of Queries Laravel Specific Model Cache 
Php :: add password php file 
Php :: loop through object php 
Php :: how did peppa pig die 
Php :: php elvis operator 
Php :: return true false laravel 
Php :: phpstorm deployment 
Php :: time dropdown in html 
Php :: declare variable in view for loop laravel 
Java :: android manifest cleartext traffic permitted 
Java :: java create directory if not exists 
Java :: how to see list of java of versions in mac 
Java :: spring enable debug log level 
Java :: how to create a button with javascri[t 
Java :: java pause 
Java :: spring boot security maven 
Java :: how to make javafx full screen default 
Java :: change port in spring boot 
Java :: Thread inline ajva 
Java :: java delay 
Java :: show dialog fragment from adapter 
Java :: java delete directory 
Java :: java add text to GUI 
Java :: how to set event priority in spigot 
Java :: android up navigation 
Java :: android plain text remove underline 
Java :: java send an image over a socket 
Java :: jfilechooser file filter 
Java :: java list addAll stream() filtereted 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =