HCE Project Python language Distributed Tasks Manager Application, Distributed Crawler Application and client API bindings.  2.0.0-chaika
Hierarchical Cluster Engine Python language binding
simple_server_test.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 
4 '''
5 HCE project, Python bindings, Distributed Crawler application.
6 Simple server listener for the GET request port 9000 application.
7 http://stackoverflow.com/questions/31371166/reading-json-from-simplehttpserver-post-data
8 
9 @package: dc
10 @author bgv bgv.hce@gmail.com
11 @link: http://hierarchical-cluster-engine.com/
12 @copyright: Copyright © 2013-2016 IOIX Ukraine
13 @license: http://hierarchical-cluster-engine.com/license/
14 @since: 0.1
15 '''
16 
17 
18 import SimpleHTTPServer
19 import SocketServer
20 import logging
21 
22 PORT = 9000
23 
24 class GetHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
25  def do_GET(self):
26  logging.error(self.headers)
27  SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
28 
29  def do_POST(self):
30  #print "got post!!"
31  content_len = int(self.headers.getheader('content-length', 0))
32  post_body = self.rfile.read(content_len)
33  #test_data = simplejson.loads(post_body)
34  logging.error(self.headers)
35  logging.error(post_body)
36  #return SimpleHTTPRequestHandler.do_POST(self)
37 
38 if __name__ == "__main__":
39  Handler = GetHandler
40  httpd = SocketServer.TCPServer(("", PORT), Handler)
41 
42  httpd.serve_forever()