Python: How do I get key/value pairs from the BaseHTTPRequestHandler HTTP POST handler?

前端 未结 2 1842
清酒与你
清酒与你 2020-11-29 01:34

given the simplest HTTP server, how do I get post variables in a BaseHTTPRequestHandler?

from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer

class         


        
2条回答
  •  旧巷少年郎
    2020-11-29 02:11

    def do_POST(self):
        ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))
        if ctype == 'multipart/form-data':
            postvars = cgi.parse_multipart(self.rfile, pdict)
        elif ctype == 'application/x-www-form-urlencoded':
            length = int(self.headers.getheader('content-length'))
            postvars = cgi.parse_qs(self.rfile.read(length), keep_blank_values=1)
        else:
            postvars = {}
        ...
    

提交回复
热议问题