testhttpserver.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # coding:utf-8
  2. import BaseHTTPServer
  3. import json
  4. import urlparse
  5. class WebRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
  6. def do_GET(self):
  7. """
  8. """
  9. print
  10. self.path
  11. parsed_path = urlparse.urlparse(self.path)
  12. print
  13. parsed_path
  14. print
  15. parsed_path.query
  16. # message_parts = [
  17. # 'CLIENT VALUES:',
  18. # 'client_address=%s (%s)' % (self.client_address,
  19. # self.address_string()),
  20. # 'command=%s' % self.command,
  21. # 'path=%s' % self.path,
  22. # 'real path=%s' % parsed_path.path,
  23. # 'query=%s' % parsed_path.query,
  24. # 'request_version=%s' % self.request_version,
  25. # '',
  26. # 'SERVER VALUES:',
  27. # 'server_version=%s' % self.server_version,
  28. # 'sys_version=%s' % self.sys_version,
  29. # 'protocol_version=%s' % self.protocol_version,
  30. # '',
  31. # 'HEADERS RECEIVED:',
  32. # ]
  33. # for name, value in sorted(self.headers.items()):
  34. # message_parts.append('%s=%s' % (name, value.rstrip()))
  35. # message_parts.append('')
  36. # message = '\r\n'.join(message_parts)
  37. data1 = [{'ip': '192.168.0.0', 'port': 456}] * 10
  38. d1 = json.dumps(data1, sort_keys=True, indent=4)
  39. message = ('192.168.1.1', 80)
  40. self.send_response(200)
  41. self.end_headers()
  42. self.wfile.write(d1)
  43. server = BaseHTTPServer.HTTPServer(('0.0.0.0', 8000), WebRequestHandler)
  44. server.serve_forever()