pythonhttpserverbasehttpserverbasehttprequesthandler

Python: BaseHTTPRequestHandler - Read raw post


How do I read the raw http post STRING. I've found several solutions for reading a parsed version of the post, however the project I'm working on submits a raw xml payload without a header. So I am trying to find a way to read the post data without it being parsed into a key => value array.


Solution

  • I think self.rfile.read(self.headers.getheader('content-length')) should return the raw data as a string. According to the docs directly inside the BaseHTTPRequestHandler class:

    - rfile is a file object open for reading positioned at the
    start of the optional input data part;