CURL.SetOptionCookieFile
------------------------

Sets the cookie file location.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [CURL](component_CURL.md) | [2.5](newinversion25.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "CURL.SetOptionCookieFile"; curl; Value { ; Encoding } ) 

**MBS**( **"CURL.SetOptionCookieFile";** /\* Sets the cookie file location. \*/  
**$curl**; /\* The CURL session handle. \*/   
**$Value**; /\* The file path to the cookie file.e.g. "/tmp/cookies.txt" \*/   
**$Encoding**) /\* Optional; The text encoding for text parameter.   
Default is UTF-8.e.g. "UTF8" \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| curl | The CURL session handle. | $curl |  |
| Value | The file path to the cookie file. | "/tmp/cookies.txt" |  |
| Encoding | The text encoding for text parameter.    Default is UTF-8.   Possible encoding names: ANSI, ISO-8859-1, Latin1, Mac, Native, UTF-8, DOS, Hex, Base64 or Windows. More listed in the [FAQ](https://www.monkeybreadsoftware.com/filemaker/faq.shtml). | "UTF8" | Optional |

### 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](https://curl.haxx.se/libcurl/c/CURLOPT_COOKIEFILE.html) 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](component_XML.md) functions or simply subsitute()   
Set Variable \[ $xml ; Value: "&lt;?xml version=\\"1.0 \\" encoding=\\"utf-8\\"?&gt; &lt;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/\\"&gt; &lt;soap:Body&gt; &lt;/soap:Body&gt; …" \]   
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](CURLNew.md)") \]   
Set Variable \[ $result ; Value: MBS ("[CURL.SetOptionURL](CURLSetOptionURL.md)"; $curl ; $url ) \]   
\# Put SOAP action and XML data type in the headers   
Set Variable \[ $result ; Value: MBS ("[CURL.SetOptionHTTPHeader](CURLSetOptionHTTPHeader.md)"; $curl ; "Content-Type: text/xml; charset=utf-8"; "Expect:"; "SOAPAction: \\""&amp; $action &amp; "\\"") \]   
\# 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](CURLSetOptionPostFields.md)"; $curl ; $xml ) \]   
\# Run transfer   
Set Variable \[ $result ; Value: MBS ("[CURL.Perform](CURLPerform.md)"; $curl ) \]   
\# Let's take a look on the cookie list   
Set Variable \[ $$cookie ; Value: MBS ("[CURL.GetCookieList](CURLGetCookieList.md)"; $curl ) \]   
Set Field \[ Curl\_Test::Cookie ; $$cookie \]   
\# Check result   
Set Field \[ Curl\_Test::Debug ; MBS ("[CURL.GetDebugMessages](CURLGetDebugMessages.md)"; $curl ) \]   
Set Variable \[ $result ; Value: MBS ("[CURL.GetResultAsText](CURLGetResultAsText.md)"; $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](component_XML.md) functions or simply subsitute()   
Set Variable \[ $xml ; Value: "&lt;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/\\"&gt; &lt;soap:Body&gt; &lt;/soap:Body&gt; &lt;/soap:Envelope&gt;" \]   
Set Field \[ Curl\_Test::XML ; $xml \]   
Set Variable \[ $action ; Value: "http://somedomain.com/partner/queryInfo" \]   
\#   
\# Setup transfer   
Set Variable \[ $result ; Value: MBS ("[CURL.SetOptionURL](CURLSetOptionURL.md)"; $curl ; $url ) \]   
\# Put SOAP action and XML data type in the headers   
Set Variable \[ $result ; Value: MBS ("[CURL.SetOptionHTTPHeader](CURLSetOptionHTTPHeader.md)"; $curl ; "Content-Type: text/xml; charset=utf-8"; "Expect:"; "SOAPAction: \\""&amp; $action &amp; "\\"") \]   
\# Set the payload for the second transfer   
Set Variable \[ $result ; Value: MBS ("[CURL.SetOptionPostFields](CURLSetOptionPostFields.md)"; $curl ; $xml ) \]   
\# Run transfer   
Set Variable \[ $result ; Value: MBS ("[CURL.Perform](CURLPerform.md)"; $curl ) \]   
\# Check result   
Set Field \[ Curl\_Test::Debug ; MBS ("[CURL.GetDebugMessages](CURLGetDebugMessages.md)"; $curl ) \]   
Set Variable \[ $result ; Value: MBS ("[CURL.GetResultAsText](CURLGetResultAsText.md)"; $curl ) \]   
Set Field \[ Curl\_Test::Resultat ; $result \]   
\# Finally end curl session   
Set Variable \[ $r ; Value: MBS ("[CURL.Release](CURLRelease.md)"; $curl ) \]  
### See also

- [CURL.SetOptionCookie](CURLSetOptionCookie.md)
- [CURL.SetOptionCookieJar](CURLSetOptionCookieJar.md)
- [CURL.SetOptionCookieList](CURLSetOptionCookieList.md)
- [CURL.SetOptionCookieSession](CURLSetOptionCookieSession.md)
- [CURL.SetOptionHTTPHeader](CURLSetOptionHTTPHeader.md)
- [CURL.SetOptionNETRCFile](CURLSetOptionNETRCFile.md)
- [CURL.SetOptionPostFields](CURLSetOptionPostFields.md)
- [CURL.SetOptionProxyCRLFile](CURLSetOptionProxyCRLFile.md)
- [CURL.SetOptionRandomFile](CURLSetOptionRandomFile.md)
- [CURL.SetOptionURL](CURLSetOptionURL.md)

### Release notes

- **Version 8.0**
    - Changed [CURL.SetOptionCAINFO](http://www.mbsplugins.eu/CURLSetOptionCAINFO.shtml), [CURL.SetOptionCAPATH](http://www.mbsplugins.eu/CURLSetOptionCAPATH.shtml), [CURL.SetOptionCookieFile](http://www.mbsplugins.eu/CURLSetOptionCookieFile.shtml), [CURL.SetOptionCookieJar](http://www.mbsplugins.eu/CURLSetOptionCookieJar.shtml), [CURL.SetOptionIssuerCert](http://www.mbsplugins.eu/CURLSetOptionIssuerCert.shtml), [CURL.SetOptionNETRCFile](http://www.mbsplugins.eu/CURLSetOptionNETRCFile.shtml), [CURL.SetOptionRandomFile](http://www.mbsplugins.eu/CURLSetOptionRandomFile.shtml), [CURL.SetOptionSSHPrivateKeyfile](http://www.mbsplugins.eu/CURLSetOptionSSHPrivateKeyfile.shtml), [CURL.SetOptionSSHPublicKeyfile](http://www.mbsplugins.eu/CURLSetOptionSSHPublicKeyfile.shtml), [CURL.SetOptionSSLCert](http://www.mbsplugins.eu/CURLSetOptionSSLCert.shtml), [CURL.SetOptionSSLKey](http://www.mbsplugins.eu/CURLSetOptionSSLKey.shtml) to use always UTF-8 on Mac/Linux and on Mac do the unicode transformation for decomposed characters to avoid trouble with special characters in file paths.

### Blog Entries

- [Let CURL handle cookie list](https://www.mbsplugins.de/archive/2019-02-28/Let_CURL_handle_cookie_list/monkeybreadsoftware_blog_filemaker)
- [LogicalDOC Webservice](https://www.mbsplugins.de/archive/2017-12-27/LogicalDOC_Webservice/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 7.6pr3](https://www.mbsplugins.de/archive/2017-12-13/MBS_FileMaker_Plugin_version_7/monkeybreadsoftware_blog_filemaker)

Created 18th August 2014 , last changed 19th April 2020

  
[CURL.SetOptionCookie](CURLSetOptionCookie.md) - [CURL.SetOptionCookieJar](CURLSetOptionCookieJar.md)

[HTML Version](CURLSetOptionCookieFile.shtml)