python - Python3 http.server POST example -


I'm converted to Python 3 App a Python 2 AP and I'm stuck with the server I

I got it Managed to get it, just fix the requests, but the post has continued to tempt me. Here I was introduced in 2.6, but 3.x that does not handle normal server POST requests I Python manual it appears from my reading should I use instead of Class A CGI server script in that directory Should also be mapped. I do not have to do this but I can not find another way. Am I missing something?

  def do_POST (self): ctype, pdict = cgi.parse_header (self.headers.get ( 'content-type')) that Sitiipi == 'multipath / form -data': query = cgi.parse_multipart (self.rfile, pdict) self.send_response (301) self.end_headers () upfilecontent = query.get ( 'upfile') print ( "filecontent", upfilecontent [0]) self Wfile.write ( "& Lt; HTML & gt; POST is OK. & Lt; BR & gt; & lt; BR & gt; "); Self.wfile.write (upfilecontent [0]); Poking and after a few hours of googling I found the following tasks:  

  def do_POST (self): length = int (self.headers [ 'content-length']) post_data = urllib.parse.parse_qs (self.rfile.read (length) .decode ( 'Utf -8 ')) # You now have a dictionary of data self.wfile.write ("Lorem Ipsum" .encode ("utf-8"))  

I' I was surprised how easy it was.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -