MadSeb
MadSeb

Reputation: 8254

RCurl sending cookie

I need to send a simple cookie using RCurl. The cookie is "AcceptDisclaimer=yes" I tried doing this:

curl <- getCurlHandle()
curlSetOpt(cookiejar='cookies.txt', curl=curl)
resultingWebPage <- postForm(website, x = result,  curl = curl)

cookies.txt contains AcceptDisclaimer=yes

However, RCurl doesn't seem to send the cookie !

Regards !

Upvotes: 1

Views: 1689

Answers (2)

Mischa Vreeburg
Mischa Vreeburg

Reputation: 1586

cookie = 'cookiefile.txt'   
curl  =  getCurlHandle ( cookiefile = cookie,
                         cookiejar = cookie,
                         useragent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en - US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"
)

# code to do something with web page

rm(curl)
gc()

Use of cookiefile will load the cookie stored in the file. Use of cookiejar will use a temporary cookie

calling rm(curl) and gc() will remove the curl session and cause the cookie file to be written to disk.

Upvotes: 3

Brian Diggs
Brian Diggs

Reputation: 58845

See How do I use cookies with RCurl? which points to http://www.omegahat.org/RCurl/RCurlJSS.pdf. Section 4.4 of that document details how cookies can be loaded. It uses the cookiefile, not cookiejar, option and the format of the file is more complicated than what you have.

Upvotes: 1

Related Questions