title: Consistent way to get request payload in Flask
body: <p>I have a Flask view that accepts some POST data. I can post the data with curl as form-encoded or JSON. How can I get the data no matter which way the client posts it?</p>
  
  <pre><code>from flask import request
  
  @app.route('/', methods=['GET', 'POST'])
  def refresh():
      # empty when posted as JSON
      print(request.form)
      # empty when posted as form-encoded
      print(request.data)
      return 'Hello, World!'
  </code></pre>
  
  <pre class="lang-none prettyprint-override"><code>curl -XPOST -H "Content-Type: application/json" 'http://127.0.0.1:5000/?thing1=1' -d '{"thing2":2}'
  curl -XPOST 'http://127.0.0.1:5000/?thing1=1' -d '{"thing2":2}'
  curl -XGET 'http://127.0.0.1:5000/?thing1=1' -d '{"thing2":2}'
  </code></pre>