title: Typhoeus with cookies?
body: <p>I have to get data out of an API which authenticates with cookies.
  Here is it works with curl.</p>
  
  <pre><code>curl -L -s -c cookie.txt "http://api.domain.com/login" -d username="user@domain.com" -d password="password"  &gt; /dev/null
  
  curl -b cookie.txt "http://api.domain.com/user_data?param1=value1" &gt; output.xml
  
  cat output.xml
  </code></pre>
  
  <p>The above works well</p>
  
  <p>However I am unable to do the same thing using Typhoeus</p>
  
  <p>I tried the following and it doesn't even authenticate. </p>
  
  <pre><code>url = "http://api.domain.com/login"
  cookie_file_path = "cookie.txt"
  params = {param1: "value1"}
  body = {username: "user@domain.com", password: "password"}
  
  request = Typhoeus::Request.new(
    url,
    method: :post,
    params: params,
    body: body,
    cookiejar: cookie_file_path,
    #headers: {Accept: "text/html"},
    verbose: true
  )
  
  response = request.run
  cookies = CookieJar.new.parse(response.headers_hash["Set-Cookie"])
  
  puts cookies # doesn't show me anything.
  
  url = "http://api.domain.com/user_data"
  cookie_file_path = "cookie.txt"
  params = {output: "xml"}
  body = {}
  
  request = Typhoeus::Request.new(
    url,
    method:        :get,
    params:        params,
    body:        body,
    cookiejar: cookie_file_path,
    cookiefile: cookie_file_path,
    #headers:       {Accept: "text/html"},
    verbose: true
  )
  </code></pre>
  
  <p>What am I missing?</p>
  
  <pre><code>&gt;&gt;&gt; response.code
  302
  &gt;&gt;&gt; response.headers_hash
  {"Server"=&gt;"squid/3.1.10", "Mime-Version"=&gt;"1.0", "Date"=&gt;"Fri, 14 Jun 2013 02:38:28 GMT", "Content-Type"=&gt;"text/html", "Content-Length"=&gt;"3830", "X-Squid-Error"=&gt;"ERR_INVALID_REQ 0", "Vary"=&gt;"Accept-Language", "Content-Language"=&gt;"en", "X-Cache"=&gt;"MISS from domain.com", "X-Cache-Lookup"=&gt;"NONE from domain.com:3128", "Via"=&gt;"1.0 domain.com (squid/3.1.10)", "Connection"=&gt;"close"}
  </code></pre>