praktikum
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Server.py 604B

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627
  1. import http.server
  2. import urllib.parse
  3. class newHandler(http.server.BaseHTTPRequestHandler):
  4. def do_GET(self):
  5. self.send_response(200)
  6. self.end_headers()
  7. parseUrl = urllib.parse.urlparse(self.path)
  8. path = parseUrl.path
  9. if path == "/Yang":
  10. msg1 = "<a href='/Ying'>" + path + "</a>"
  11. elif path == "/Ying":
  12. msg1 = "<a href='/Yang'>" + path + "</a>"
  13. self.wfile.write(msg1.encode('utf-8'))
  14. PORT = 4096
  15. HANDLER = newHandler
  16. ADDRESS = ('', PORT)
  17. SERVER = http.server.HTTPServer(ADDRESS, HANDLER)
  18. SERVER.serve_forever()