title: Session dying when using curl from command line
body: <p>I mad a simple java web app using <a href="http://sparkjava.com/" rel="nofollow">sparkjava</a>.  It fields GET and POST requests.  I made my own simple authentication script, which authenticates the user using the secret password and stores the username in the session:</p>
  
  <pre><code>    /*
      Make sure authenticated
      */
      before((req, res) -&gt; {
          boolean authenticated = false;
          if ( req.session().attribute("user") != "casumo_user" ) {
              try{
                  if (req.queryParams("secret").equals(System.getenv().get("SECRET"))){
                      authenticated = true;
                      req.session().attribute("user","casumo_user");
                  }
              }catch (Exception e){
                  halt(401, "{\"error\":\"Please Authenticate.\"}");
              }
          }else{
              authenticated = true;
          }
  
          if (!authenticated) {
              halt(401, "{\"error\":\"Please Authenticate.\"}");
          }
      });
  </code></pre>
  
  <p>I was using the <a href="https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en" rel="nofollow">Postman Add-on for Chrome</a>, and this was working fine.  I would authenticate once, and the server would keep my session alive for subsequent requests.</p>
  
  <p>The problem is I wanted to use curl to make the same requests, but the session was not staying alive from one request to another.</p>
  
  <p>For example, first I use this command:</p>
  
  <pre><code>curl -s -L --data "secret=secret_password" url/auth | jsonpp 
  </code></pre>
  
  <blockquote>
    <p>{ "msg": "Authenticated! You can now make requests." }</p>
  </blockquote>
  
  <p>But then making a sebsequent GET request proves that the session is not preserved/</p>
  
  <pre><code>curl -s -L url/films | jsonpp 
  </code></pre>
  
  <blockquote>
    <p>{ "error": "Please Authenticate." }</p>
  </blockquote>
  
  <p>Using the Postman App would allow me to make GET and POST requests for quite some time after authenticating 1 time.  Is it possible to do this using curl from the command line like I have here?  Or is my authentication system not robust enough to use curl from the command line?</p>
  
  <p>Thanks!</p>
  
  <p><a href="https://github.com/jefferythewind/movie_rental" rel="nofollow">The project is on GitHub.</a></p>