[R] RCurl and cookies in POST requests

Duncan Temple Lang duncan at wald.ucdavis.edu
Mon Nov 15 02:02:06 CET 2010

Hi Christian

 Thanks for finding this. The problem seems to be that the finalizer
on the curl handle seems to disappear and so is not being called
when the handle is garbage collected.  So there is a bug somewhere
and I'll try to hunt it down quickly.

  In the meantime, you can achieve the same effect by calling the
C routine curl_easy_cleanup.  You can't do this directly with a
.Call() or .C() as there is no explicit interface in the RCurl
package to this routine. However, you can use the Rffi package
(on the omegahat  repository)

 cif = CIF(voidType, list(pointerType))
 callCIF(cif, "curl_easy_cleanup", curl at ref)

 I'll keep looking for why the finalizer is getting discarded.

 Thanks again,


On 11/14/10 6:30 AM, Christian M. wrote:
> 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.
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list