title: Using CURL to download file and view headers and status code
body: <p>I'm writing a Bash script to download image files from <a href="http://snapito.com" rel="noreferrer">Snapito</a>'s web page snapshot API.  The API can return a variety of responses indicated by different HTTP response codes and/or some custom headers.  My script is intended to be run as an automated Cron job that pulls URLs from a MySQL database and saves the screenshots to local disk.</p>
  
  <p>I am using <code>curl</code>.  I'd like to do these 3 things using a single CURL command:</p>
  
  <ol>
  <li>Extract the HTTP response code</li>
  <li>Extract the headers</li>
  <li>Save the file locally (if the request was successful)</li>
  </ol>
  
  <p>I could do this using multiple <code>curl</code> requests, but I want to minimize the number of times I hit Snapito's servers.  Any <code>curl</code> experts out there?</p>
  
  <p>Or if someone has a Bash script that can respond to the full documented set of Snapito API responses, that'd be awesome.  Here's <a href="http://snapito.com/paid-api.jsp" rel="noreferrer">their API documentation</a>.</p>
  
  <p>Thanks!</p>