Created
November 28, 2010 12:19
-
-
Save vvoody/718871 to your computer and use it in GitHub Desktop.
recording the http request(GET/POST)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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