Saving Cookies

I’m trying to log into a website with username and password, then store a cookie and download a file. This used to work using —cookiejar.

Reportedly, the latest version of FMS won’t store cookies using —cookiejar. Therefore, I need to parse the cookie from the header.

Anybody know exactly what portion of the header / cookie I need to extract?

You can use MBS FileMaker Plugin as we have the CURL.SetOptionCookieFile function:

Set Variable [ $r; Value: MBS( "CURL.SetOptionCookieFile"; $curl; "") ]

so you have a cookie storage in memory for the $curl, which you can use for multiple requests.

  • Wondering if this Community post might help

  • Alternatively: Would it be possible to run the process on an FMP client which does still save the cookiejar data to a variable, and use that as a point of reference to compare the full returned header to the cookiejar data (and from that, infer the answer)?


I’m running the script locally, but FMP is not saving the cookie. My script used to work perfectly, so I believe this issue may have been propagated to FMP. If I can’t parse the cookie out of the header, I’ll try downloading MBS.

Edit: I missed the fact that --cookie-jar stopped working when run serverside. Using headers looks promising

just to confirm correct syntax, are you spelling the curl option like this, with the hyphen in the middle?

--cookie-jar $cookieJar

That should give you the cookie, which you can then pass to the net request like this:

Set Variable [ $cookie ; Substitute ( $cookieJar ; ¶ ; Char(10) ) ]
Set variable [ $curl ; "--cookie $cookie ]
Insert From Url [ ... ]
1 Like

Yes, that’s the format I’m using. That script used to work perfectly, and now fails to load the cookie. I was able to use a workaround to parse the cookie from the header. Now, however, when I pass the cookie to a second Insert From URL script step, the script seems to be logging in correctly, but the text file is not loaded. I’ve confirmed the URL for the text file, so I’m not sure what’s happening at this point.

1 Like

According to some posts online, only PSOS on FMS fails to store the cookie. However, I’m definitely experiencing the same issue with FMP on Windows.

I’ll double check, but I’m sure I was using that syntax. Here’s workaround I used:

1 Like

“-L -D $responseHeader2 “ & “-H\”Cookie: & $requestCookie & “\””

returns “user not logged in”

However, if I send just the header with the cookie, I seem to stay logged in. So that works. Need to figure out how to allow for the redirect.

Any suggestions?

Hi @steverichter ,

Could you give us an idea of what the returned headers are when you perform the request without the -L option?

I am thinking that, if you are receiving a 302 response, that there's a reasonable chance that the response headers will include a Location header which will supply you with the next URL that you'd need to connect to (and while doing so, continuing to pass along any cookies that apply).

This makes for a more laborious task to get to the data that you want, and normally I would think that this should not be necessary, but, if the cookie jar functionality is not working as it once did, I feel that all bets may have to be off with respect to my usual expectations for this type of endeavor.

Also, on a separate matter:

I'd like to encourage you to adopt the habit of not using $variables (that is, variables with $ or $$ scope) in your Let or While calculations, unless there really is a need to do so. In many/most cases of using Let or While, all that is needed are variables that do not have the $ or $$ prefix. Whenever this is so, it is a good habit to use variables that are not scoped to the level that $ or $$ variables have.

Hope some of the above may help.

1 Like

1 Like