I am trying to communicate with a RESP API using cURL calls via PHP.
The first call to the API is to login by passing a username and a password. Once the API receive my request, it returns something like this in the headers
HTTP/1.1 201 Created
ININ-ICWS-CSRF-Token: WAhtYWxoabcfa1dBY2NvUkRJWCQ2Yzg5YefgOC01YTI0LTQ1MjEtYTdgdd1iMzAyNGRhZmRjZTBYCjEwLjAuNC4xNjA=
ININ-ICWS-Session-ID: 2562886002
Set-Cookie: icws_2562886002=1924Pe25-d47c-4d07-9546-9fcuijfdd0b02; Path=/icws/2562886002
Location: /icws/2562886002/connection
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Content-Type: application/vnd.inin.icws+JSON; charset=utf-8
Date: Thu, 14 May 2015 17:49:20 GMT
Server: HttpPluginHost
Content-Length: 238
Now, along with any additional call to the API, the cookie value that was returned in the header must be included in the new request. (in this case: icws_2562886002=1924Pe25-d47c-4d07-9546-9fcuijfdd0b02
)
How can I configure my cURL call to automatically pass back the cookie that is received?
therefore, with every request I will see to have Cookie: icws_2562886002=1924Pe25-d47c-4d07-9546-9fcuijfdd0b02
in the header.
I know I can manually added it like this
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Cookie: icws_2562886002=1924Pe25-d47c-4d07-9546-9fcuijfdd0b02'));
But there has to be a way for the cURL to automatically add the cookie value to the request.
I also tried to add this
curl_setopt($ch, CURLOPT_COOKIE, true);
But did not work either