How can I debug POST requests with python's BaseHTTPServer / SimpleHTTPServer?

前端 未结 2 1834
长发绾君心
长发绾君心 2021-02-02 16:11

I found a script on this site for running a simple server via the command line with python.

I added some print lines in because I\'d like to print out the G

2条回答
  •  温柔的废话
    2021-02-02 16:25

    You can use cgi module instead of urlparse. cgi implements POST params parsing out of the box. Using well-tested libraries seems better.

    import cgi

    def do_POST(self):
        form = cgi.FieldStorage(
            fp=self.rfile,
            headers=self.headers,
            environ={"REQUEST_METHOD": "POST"}
        )
    
        for item in form.list:
            print "%s=%s" % (item.name, item.value)
    

提交回复
热议问题