Parse http GET and POST parameters from BaseHTTPHandler?

前端 未结 5 1310
春和景丽
春和景丽 2020-12-08 07:10

BaseHTTPHandler from the BaseHTTPServer module doesn\'t seem to provide any convenient way to access http request parameters. What is the best way to parse the GET paramete

5条回答
  •  生来不讨喜
    2020-12-08 07:17

    Better solution to an old question:

    def do_POST(self):
        length = int(self.headers.getheader('content-length'))
        field_data = self.rfile.read(length)
        fields = urlparse.parse_qs(field_data)
    

    This will pull urlencoded POST data from the document content and parse it a dict with proper urldecoding

提交回复
热议问题