SHARE
TWEET

Untitled

a guest Jan 8th, 2011 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import cgi
  2. import cStringIO
  3. import SocketServer
  4. import SimpleHTTPServer
  5.  
  6.  
  7. class RequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
  8.  
  9.     def do_POST(self):
  10.         ctype, pdict = cgi.parse_header(self.headers.getheader('content-type'))
  11.         if ctype != 'multipart/form-data':
  12.             return
  13.  
  14.         body = cgi.parse_multipart(self.rfile, pdict)
  15.         print body
  16.  
  17.         reply = cStringIO.StringIO()
  18.         reply.write(str(body))
  19.  
  20.         self.send_response(200)
  21.         self.send_header('Content-type', 'text/html')
  22.         self.send_header('Content-length', reply.tell())
  23.         self.end_headers()
  24.  
  25.         reply.seek(0)
  26.         self.copyfile(reply, self.wfile)
  27.  
  28.  
  29. class Server(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
  30.     pass
  31.  
  32.  
  33. srv = Server(('localhost', 8080), RequestHandler)
  34. srv.serve_forever()
  35.  
  36. srv_thread = threading.Thread(target=srv.serve_forever)
  37. srv_thread.start()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top