zoukankan      html  css  js  c++  java
  • python web.py实现简单的get和post请求

    使用web.py框架,实现简单的get和post请求:

    py文件名:mytest.py

     1 import web
     2 urls = (
     3      '/', 'hello'
     4 )
     5 app = web.application(urls, globals())
     6 
     7 class hello:
     8     def GET(self):
     9         a = int(web.input().a)
    10         b = int(web.input().b)
    11         return a + b
    12 
    13     def POST(self):
    14         a = int(web.input().a)
    15         b = int(web.input().b)
    16         return a + b
    17 
    18 if __name__ == "__main__":
    19     app.run()

    默认端口号为8080,可以使用命令行运行py文件,更改端口号,例如:

    python mytest.py 8888

    将端口号改为8888,在浏览器中访问get请求,返回结果为:

     使用postman或jmeter访问post请求,返回结果为:

    需要注意的是,每次代码更新后,都需要重新运行py文件

  • 相关阅读:
    windows nginx
    stdClass 标准
    array_merge
    array_pop
    array_push
    array_unique
    GMT与UTC简介(转)
    curl-手册
    13.5. zipfile — Work with ZIP archives
    7. Input and Output
  • 原文地址:https://www.cnblogs.com/benben-wu/p/10220006.html
Copyright © 2011-2022 走看看