Categories
Python Answers

How to get raw POST body in Python Flask regardless of Content-Type header?

Spread the love

Sometimes, we want to get raw POST body in Python Flask regardless of Content-Type header.

In this article, we’ll look at how to get raw POST body in Python Flask regardless of Content-Type header.

How to get raw POST body in Python Flask regardless of Content-Type header?

To get raw POST body in Python Flask regardless of Content-Type header, we call request.stream.read.

For instance, we write

data = request.stream.read()

to get the raw data from the request that’s passed by the WSGI server to the Flask app and read it.

Conclusion

To get raw POST body in Python Flask regardless of Content-Type header, we call request.stream.read.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *