Reputation: 29
I am calling this API by curl:
$url = '/api/auth/login';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\"fbUserID\": \"$fbID\", \"fbAccessToken\": \"$Token\"}",
CURLOPT_HTTPHEADER => array(
"accept: application/json",
"cache-control: no-cache",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$jsonresult = json_decode($response);
$err = curl_error($curl);
My question is how can I get the cookie value in response header, I am testing call in POSTMAN API so I am getting cookie value.
Can you please help?
Upvotes: 1
Views: 2670
Reputation: 1933
Add this code segment
$cookie=dirname(__FILE__)."/cookie.txt";
curl_setopt ($curl, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($curl, CURLOPT_COOKIEFILE, $cookie);
It will look like this finally
$cookie=dirname(__FILE__)."/cookie.txt";
$url = '/api/auth/login';
$curl = curl_init();
curl_setopt_array($curl,
array( CURLOPT_URL => $url
, CURLOPT_COOKIEJAR => $cookie
, CURLOPT_COOKIEFILE => $cookie
, CURLOPT_RETURNTRANSFER => true
, CURLOPT_ENCODING => ""
, CURLOPT_MAXREDIRS => 10
, CURLOPT_TIMEOUT => 30
, CURLOPT_CUSTOMREQUEST => "POST"
, CURLOPT_POSTFIELDS => "{\"fbUserID\": \"$fbID\", \"fbAccessToken\": \"$Token\"}"
,CURLOPT_HTTPHEADER => array(
"accept: application/json",
"cache-control: no-cache",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$jsonresult = json_decode($response);
$err = curl_error($curl);
Upvotes: 1