title: How do I use cookies with RCurl?
body: <p>I am trying to write an R package that accesses some data via a REST API. The API, however, doesn't use http authentication, but rather relies on cookies to keep credentials with the session.</p>
  
  <p>Essentially, I'd like to replace the following two lines from a bash script with two R functions: One to perform the login, and store the session cookie, and the second to GET the data.</p>
  
  <pre><code>curl -X POST -c cookies.txt -d"username=xxx&amp;password=yyy" http://api.my.url/login
  curl         -b cookies.txt                               http://api.my.url/data
  </code></pre>
  
  <p>I'm clearly not understanding how RCurl works with curl options. My script as it stands has:</p>
  
  <pre><code>library(RCurl)
  curl &lt;- getCurlHandle()
  curlSetOpt(cookiejar='cookies.txt', curl=curl)
  postForm("http://api.my.url/login", username='xxx', password='yyy', curl=curl)
  getURL('http://api.my.url/data", curl=curl)
  </code></pre>
  
  <p>The final <code>getURL()</code> fails with a "Not logged in." message from the server, and after the <code>postForm()</code> no <code>cookies.txt</code> file exists.</p>