testhttpserver.py 1.6 KB

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