jeudi 18 janvier 2018

How to access cookie value from API response using PHP?

I made a post to a an API with this code

 curl_setopt_array($curl, array(
    CURLOPT_PORT => "8443",
    CURLOPT_URL => "https://1.1.1.1:3000/api/public/v1_0/session",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_VERBOSE => FALSE,
    CURLOPT_SSL_VERIFYPEER => FALSE,
    CURLOPT_SSL_VERIFYHOST => FALSE,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => "{\n  \"username\" : \"admin\",\n  \"password\" : \"1234567890\", \n  \"apiVersions\" : [ \"1\", \"2\" ],\n  \"timeZoneUtcOffset\" : \"-00:00\"\n}",
    CURLOPT_HTTPHEADER => array(
      "cache-control: no-cache",
      "content-type: application/json;charset=UTF-8",
      "cookie: JSESSIONID={JSESSIONID}",
    ),
  ));

  $response = curl_exec($curl);
  $err = curl_error($curl);

  curl_close($curl);

  if ($err) {
  echo "cURL Error #:" . $err;
  } else {
  echo $response;
  }

I can seems to get the response fine, but I had some issue retriveing the cookies.

I've tried

// var_dump($_SERVER);
// print_r($GLOBALS);
// dd(Request::cookie());

Nothing seems to work.

I am trying to access this value that I got back programmatically via PHP

enter image description here


Questions

How would one go about and retrieve the cookie from API response ?


I'm open to any suggestions at this moment.

Any hints/suggestions / helps on this be will be much appreciated!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2DgUykQ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire