Skip to content
Prev 241501 / 398500 Next

RCurl and cookies in POST requests

Hello.

I know that it's usually possible to write cookies to a cookie
file by removing the curl handle and doing a gc() call. I can do
this with getURL(), but I just can't obtain the same results with
postForm().

If I use:

curlHandle <- getCurlHandle(cookiefile=FILE, cookiejar=FILE)

and then do:

getURL(http://example.com/script.cgi, curl=curlHandle)
rm(curlHandle)
gc()

it's OK, the cookie is there. But, if I do (same handle; the
parameter is a dummy):

postForm(site, .params=list(par="cookie"), curl=curlHandle,
  style="POST")
rm(curlHandle)
gc()

no cookie is written.

Probably I'm doing something wrong, but don't know what.

Is it possible to store cookies read from the output of a
postForm() call? How?

Thanks.

Christian

PS.: I'm attaching a script that can be sourced (and its .txt
version). It contains an example. The expected result is a file
(cookies.txt) with two cookies. The script currently uses
getURL() and two cookies are stored. If postForm() is used
(currently commented), only 1 cookie is written.