Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server   Client   Old   Guides   Examples
New in version: 7.5   8.0   8.1   8.2   8.3   8.4   8.5   9.0   9.1   9.2    Statistic  

CURL.SetOptionCookieFile

Sets the cookie file location.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
CURL 2.5 Yes Yes Yes Yes Yes
MBS( "CURL.SetOptionCookieFile"; curl; Value { ; Encoding } )   More

Parameters

Parameter Description Example value
curl The CURL session handle. $curl
Value The file path to the cookie file. "/tmp/cookies.txt"
Encoding Optional
The text encoding for text parameter.
Default is UTF-8.
Possible encoding names: ANSI, Arabic-Mac, Arabic-Win, Baltic-Win, CentralEurope-Mac, ChineseSimp-Mac, ChineseSimp-Win, ChineseTrad-Mac, ChineseTrad-Win, Cyrillic-Mac, Cyrillic-Win, EasternEurope-Win, Greek-Mac, Greek-Win, Hebrew-Mac, Hebrew-Win, ISO-8859-1, ISO-8859-2, ISO-8859-3, ISO-8859-4, ISO-8859-5, ISO-8859-6, ISO-8859-7, ISO-8859-8, ISO-8859-9, ISO-8859-15, Korean-Johab, Korean-Mac, Korean-Win, Latin1, Mac, Native, ShiftJIS-Mac, ShiftJIS-Win, Turkish-Mac, Turkish-Win, UTF-8, DOS or Windows. Pass native to use the native encoding of the current platform.
"UTF8"

Result

Returns "OK" on success.

Description

Sets the cookie file location.
Pass a file path for the cookie file. It should contain the name of your file holding cookie data to read. The cookie data may be in Netscape / Mozilla cookie data format or just regular HTTP-style headers dumped to a file.

Given an empty or non-existing file or by passing the empty string (""), this option will enable cookies for this curl handle, making it understand and parse received cookies and then use matching cookies in future requests.

If you use this option multiple times, you just add more files to read. Subsequent files will add more cookies.

Starting with version 8.0 the plugin will always use UTF-8 encoding for file path on Linux and macOS. For macOS we also do the unicode character normalization for file names for you.

See also COOKIEFILE option in CURL manual.

Examples

Activate cookie engine without cookie file:

MBS( "CURL.SetOptionCookieFile"; $curl; "")

Perform SOAP service with login and use cookies in second request:

# The URL of the service
Set Variable [ $url ; Value: "http://somedomain.com/PartnerService17.asmx" ]
# Build XML for SOAP Login request, e.g. with MBS XML functions or simply subsitute()
Set Variable [ $xml ; Value: "<?xml version=\"1.0\" encoding=\"utf-8\"?> <soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> <soap:Body> </soap:Body> …" ]
Set Field [ Curl_Test::XML ; $xml ]
# The SOAP action to use
Set Variable [ $action ; Value: "http://somedomain.com/partner/loginWithLicenceUnlockInfo" ]
#
# Setup transfer
Set Variable [ $curl ; Value: MBS("CURL.New") ]
Set Variable [ $result ; Value: MBS("CURL.SetOptionURL"; $curl; $url) ]
# Put SOAP action and XML data type in the headers
Set Variable [ $result ; Value: MBS("CURL.SetOptionHTTPHeader"; $curl; "Content-Type: text/xml; charset=utf-8"; "Expect:"; "SOAPAction: \""& $action & "\"") ]
# Ask CURL to manage cookies
Set Variable [ $result ; Value: MBS("CURL.SetOptionCookieFile"; $curl; "" ) ]
# Set the payload for the login transfer
Set Variable [ $result ; Value: MBS("CURL.SetOptionPostFields"; $curl; $xml) ]
# Run transfer
Set Variable [ $result ; Value: MBS("CURL.Perform"; $curl) ]
# Let's take a look on the cookie list
Set Variable [ $$cookie ; Value: MBS("CURL.GetCookieList"; $curl ) ]
Set Field [ Curl_Test::Cookie ; $$cookie ]
# Check result
Set Field [ Curl_Test::Debug ; MBS("CURL.GetDebugAsText"; $curl) ]
Set Variable [ $result ; Value: MBS("CURL.GetResultAsText"; $curl) ]
Set Field [ Curl_Test::Resultat ; $result ]
#
# Reuse same $curl for second request reusing existing cookies
#
# Make new XML for second request
Set Variable [ $npk ; Value: "103" ]
# Build XML for SOAP Login request, e.g. with MBS XML functions or simply subsitute()
Set Variable [ $xml ; Value: "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"> <soap:Body> </soap:Body> </soap:Envelope>" ]
Set Field [ Curl_Test::XML ; $xml ]
Set Variable [ $action ; Value: "http://somedomain.com/partner/queryInfo" ]
#
# Setup transfer
Set Variable [ $result ; Value: MBS("CURL.SetOptionURL"; $curl; $url) ]
# Put SOAP action and XML data type in the headers
Set Variable [ $result ; Value: MBS("CURL.SetOptionHTTPHeader"; $curl; "Content-Type: text/xml; charset=utf-8"; "Expect:"; "SOAPAction: \""& $action & "\"") ]
# Set the payload for the second transfer
Set Variable [ $result ; Value: MBS("CURL.SetOptionPostFields"; $curl; $xml) ]
# Run transfer
Set Variable [ $result ; Value: MBS("CURL.Perform"; $curl) ]
# Check result
Set Field [ Curl_Test::Debug ; MBS("CURL.GetDebugAsText"; $curl) ]
Set Variable [ $result ; Value: MBS("CURL.GetResultAsText"; $curl) ]
Set Field [ Curl_Test::Resultat ; $result ]
# Finally end curl session
Set Variable [ $r ; Value: MBS("CURL.Cleanup"; $curl) ]

See also

Blog Entries

Created 18th August 2014, last changed 28th February 2019


CURL.SetOptionCookie   -   CURL.SetOptionCookieJar

Feedback: Report problem or ask question.




Links
MBS FileMaker blog