GET

  1. import json
  2. from urllib import parse
  3. from wsgiref.simple_server import make_server
  4. def application(env, start_response):
  5. # 定义文件请求类型和当前请求成功的code
  6. start_response('200 ok', [('Content-Type', 'text/html')])
  7. # 获取当前get请求的所有数据,返回是string类型
  8. parmas = parse.parse_qs(env['QUERY_STRING'])
  9. # 获取get中key为name的值
  10. name = parmas.get('name', [''])[0]
  11. no = parmas.get('no', [''])[0]
  12. # 组成一个字典
  13. dic = {'name': name,
  14. 'no': no}
  15. return [json.dumps(dic)]
  16. if __name__ == "__main__":
  17. port = 5088
  18. httpd = make_server('0.0.0.0', port, application)
  19. print("serving http on port {}".format(str(port)))
  20. httpd.serve_forever()

POST