Note that there are some explanatory texts on larger screens.

plurals
  1. POTyphoeus with cookies?
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload