title: httr: retrieving data with POST()
body: <p>Disclaimer: while I have managed to grab data from another source using httr's POST function, let it be known that I am a complete n00b with regards to httr and HTML forms in general.</p>
  
  <p>I would like to bring some data directly into R from a website using httr. My first attempt involved passing a named list to the body arg (as is shown in <a href="http://cran.r-project.org/web/packages/httr/vignettes/quickstart.html" rel="noreferrer">this vignette</a>). However, I noticed square brackets in the form input names (at least I <em>think</em> they're the form input arguments). So instead, I tried passing in the body as a string as I think it should appear in the request body:</p>
  
  <pre><code>url &lt;- 'http://research.stlouisfed.org/fred2/series/TOTALSA/downloaddata'
  query &lt;- paste('form[native_frequency]=Monthly', 'form[units]=lin',
                  'form[frequency]=Monthly', 'form[obs_start_date]="1976-01-01"',
                  'form[obs_end_date]="2014-11-01"', 'form[file_format]=txt'
                  sep = '&amp;')
  response &lt;- POST(url, body = query)
  </code></pre>
  
  <p>In any case, the above code just returns the webpage source code and I cannot figure out how to properly submit the form so that it returns the same data as manually clicking the form's 'Download Data' button. </p>
  
  <p>In Developer Tools/Network on Chrome, it states in the Response Header under Content-Disposition that there is a text file attachment containing the data when I manually click the 'Download Data' button on the form. It doesn't appear to be in any of the headers associated with the response object in the code above. Why isn't this file getting returned by the POST request--where's the file with the data going?</p>
  
  <p>Feels like I'm missing something obvious. Anyone care to help me connect the dots?</p>