Skip to content

Instantly share code, notes, and snippets.

@vvoody
Created November 28, 2010 12:19
Show Gist options
  • Save vvoody/718871 to your computer and use it in GitHub Desktop.
Save vvoody/718871 to your computer and use it in GitHub Desktop.
recording the http request(GET/POST)
#!/usr/bin/python
# -*- coding: utf-8 -*-
from BaseHTTPServer import HTTPServer,BaseHTTPRequestHandler
class MyHttpHandler(BaseHTTPRequestHandler):
def do_GET(self):
print self.headers
print self.path
self.send_response(200)
def do_POST(self):
print '~~~~~~~~~~~~'
print self.headers
content_length = self.headers.getheader('content-length')
if content_length:
content_length = int(content_length)
else:
print 'POST ERROR: missing content-length'
return
input_body = self.rfile.read(content_length)
print input_body
self.send_response(200)
httpd=HTTPServer(('',8080),MyHttpHandler)
print('Server started port 8080…..')
httpd.serve_forever() #启动http服务器
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment