Python简单http服务实现
2020-12-13 01:48
                         标签:import   cal   creat   get   rom   __name__   tar   hand   _for    1、代码实现 浏览器调用: http://localhost:8888/ 返回如下内容: Python简单http服务实现 标签:import   cal   creat   get   rom   __name__   tar   hand   _for    原文地址:https://www.cnblogs.com/wangymd/p/11011616.html# -*- coding: utf-8 -*-
"""
Created on Tue Jun 11 18:12:01 2019
@author: wangymd
"""
from http.server import HTTPServer, BaseHTTPRequestHandler
import json
data = {‘result‘: ‘this is a http server test‘}
host = (‘localhost‘, 8888)
class Resquest(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header(‘Content-type‘, ‘application/json‘)
        self.end_headers()
        self.wfile.write(json.dumps(data).encode())
if __name__ == ‘__main__‘:
    server = HTTPServer(host, Resquest)
    print("Starting http server, listen at: %s:%s" % host)
    server.serve_forever()
2、测试{"result": "this is a http server test"}
下一篇:算法的时间复杂度O