1

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?

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.