Get raw POST body in Python Flask regardless of Content-Type header
Question: So, while ago I asked similar question: [How to get whole request POST body in
Python (Flask)](http://stackoverflow.com/questions/10434599/how-to-get-whole-
request-post-body-in-python-flask)

And I got an answer that actually `flask.request.data` is the raw POST BODY.
But that seems to work only if the request has few additional headers:

    
    
    headers = {
        'Content-type': 'binary/octet-stream',
        'Content-length': len(postBody),
        'Content-transfer-encoding': 'binary',
    }
    

If those headers are not present, the `flask.request.data` will be empty:

    
    
    from flask import Flask
    
    app = Flask(__name__)
    @app.route('/', methods=['POST'])
    def parse_request():
        data = flask.request.data # but data will be empty unless the request has the proper content-type header...
    

So now I found the request is actually `application/x-www-form-urlencoded`
(which is default mimetype) then I could take the data like this:

    
    
    app = Flask(__name__)
    @app.route('/', methods=['POST'])
    def parse_request():
        data = flask.request.data # but data will be empty unless the request has the proper content-type header...
        if not data:
            data = request.form.keys()[0]
    

But I'm not sure that I could count on it...

So, is there a way to be able to obtain the raw post body of any post request,
regardless of the headers?


Answer: I'm using Flask 0.10.1, and if you look at the source code, it turns out that
you can call

    
    
    request.get_data()
    

To get the raw data, regardless of content type. The request data is then
cached, and you can subsequently access `request.data, request.json,
request.form` at will.

However, if you access `request.data` first, it will call `get_data` with
different options, where the form parsing runs first, and the actual request
data read from the stream is never stored; `request.form, request.json` etc.
then has nothing to work with.

