zoukankan      html  css  js  c++  java
  • Python简单http服务实现

    1、代码实现

    # -*- 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、测试

    浏览器调用:

    http://localhost:8888/

    返回如下内容:

    {"result": "this is a http server test"}
    
    
  • 相关阅读:
    ORACLE函数<四>
    Oracle中的伪列<三>
    PL/SQL<八>函数
    invoice
    quite
    做人小结
    wsdl 学习笔记
    name, middle name, first name, last name
    小感叹
    qualified、quantity
  • 原文地址:https://www.cnblogs.com/wangymd/p/11011616.html
Copyright © 2011-2022 走看看