python - SimpleHTTPServer and SocketServer -
i have created 'handler' python script follows:
import simplehttpserver import socketserver port = 8000 handler = simplehttpserver.simplehttprequesthandler httpd = socketserver.tcpserver(("", port), handler) print "serving @ port:", port httpd.serve_forever() i have javascript function, sends info server url request. works fine, when run handler script, , javascript, can see of info js in terminal:
localhost.localadmin - - [20/feb/2013] "get /?var=data/ http/1.1" 200 - what do, able access info handler script, ideally somethig this:
data = httpd.server_forever() #how do somethign how accomplish such thing?
you can inherit simplehttpserver.simplehttprequesthandler this:
class myhandler(simplehttpserver.simplehttprequesthandler): def do_get(self): # code here print "client requested:", self.command, self.path simplehttpserver.simplehttprequesthandler.do_get(self) port = 8000 httpd = socketserver.tcpserver(("", port), myhandler) print "serving @ port:", port httpd.serve_forever() that print in console:
client requested /?var=data/ check documentation on simplehttprequesthandler , basehttprequesthandler more information.
python python-2.7 socketserver simplehttpserver
No comments:
Post a Comment