title: use curl with cookies
body: <p>I'm trying to use curl to authenticate my web server on order to do some secured requests using curl.</p>
  
  <p>To authenticate I use the following command:</p>
  
  <pre><code>curl -c cookie.txt -H 'Content-Type: application/json' --data -d "{\"admin_user\" : { \"email\" : \"example@example.com\", \"password\" : \"very_secured\"}}" -X POST http://localhost:3000/admin/login 
  </code></pre>
  
  <p>The authentication works well. I see that the server creates a new session Id. </p>
  
  <pre><code>UPDATE "admin_users" SET "last_sign_in_at" = '2015-11-12 19:41:32.927958', "current_sign_in_at" = '2015-11-12 20:04:32.798444', "sign_in_count" = 317, "updated_at" = '2015-11-12 20:04:32.861759' WHERE "admin_users"."id" = 13
  </code></pre>
  
  <p>So I then try to reuse the cookie I receive from the response to retrieve some data from my server:</p>
  
  <pre><code>curl -b cookie.txt  'http://127.0.0.1:3000/admin/my_secured_page'
  </code></pre>
  
  <p>Nevertheless I get redirected back to the login page with an error 401:
  Completed 401 Unauthorized in 4.6ms</p>
  
  <p>I tried to compare what I'm doing with what Firefox and Chrome do but I don't see any difference on the authentication procedure.</p>
  
  <p>When I use a cookie retrieve by Chrome or Firefox it works, but the ones generated by curl don't.</p>
  
  <p>I even tried to edit a cookie generated by curl to edit the session id to a session Identifier copied from a chrome cookie, and that works too.</p>
  
  <p>When I compare on the request headers the cookie returned by the login page and the one I send to the secured page, they have the same value.</p>
  
  <p>does anybody have any clue on what I'm doing wrong?</p>