Python contains one helpful module: SimpleHTTPServer. You can expose local directory via HTTP by the following command:
Python will start HTTP server at http://localhost:8000
It is very worthy when you’re doing some tests of web application.
The only problem is that SimpleHTTPServer does not support POST. Sometimes it’s very useful to see the content of POST request.
Is there any simple way how to achieve this in Python?
Here is a small extension of SimpleHTTPServer with do_POST handler:
You can download SimpleServer.py here and start it with command:
Many thanks for the above example.
How do you access the data that has been posted?
I’ve tried the above and it seems to work but I can’t work out how to get at the information that has been posted. Do fp, headers and environ have to match the data format?
@Tim: Checkout CGI module for Python – http://docs.python.org/2/library/cgi.html
Example in this article is using cgi.FieldStorage to parser request and create form with fields.
Try to access self.headers.
The easiest way how to see available data and objects is to open that script in Debug Mode in IntelliJ Idea with Python plugin or in Eclipse with PyDev.