返回顶部
扶摇直上九万里,展翅高飞岂可待。

接口测试——postman接口测试(三)

1. postman介绍与安装

1675512564688.png

2. postman发送get请求

import pymysql
from flask import Flask,request

# 这里是mysql的基本连接信息
conn = pymysql.connect(
    host="192.168.1.116",
    user="root",
    password="123",
    database="nydb1",
    charset="utf8"
)


cursor = conn.cursor()


app = Flask(__name__)

@app.route("/")
def hello_world():

    sel = "select * from school"
    result = cursor.execute(sql)
    # 得到查询后的真正的结果
    r = cursor.fetchall()
    print(r)
    return str(r)


@app.route("/mypost",methods=["post"])
def my_post():
    return "post request"

@app.route("/mypost1",methods=["post"])
def my_post1():
    # 表单数据类型
    username =request.form["username"]
    sex = request.form["sex"]
    print(username)
    print(sex)
    return "post request" + username + "::" + sex




@app.route("/mypost1",methods=["post"])
def my_post2():
    # json数据类型
    request_data =request.get_json()
    sex = request.form["sex"]
    print(request_data)
    print(request_data["user"])
    return "post request" + str(request_data)

@app.route("/mypost",methods=["post"])
def my_post():
    return "post request"

@app.route("/mypost1",methods=["post"])
def my_post1():
    # 表单数据类型
    username =request.form["username"]
    sex = request.form["sex"]
    print(username)
    print(sex)
    return "post request" + username + "::" + sex




@app.route("/mypost1",methods=["post"])
def my_post2():
    # json数据类型
    request_data =request.get_json()
    sex = request.form["sex"]
    print(request_data)
    print(request_data["user"])
    return "post request" + str(request_data)

if __name__ == "__main__":
    app.run()
  • 执行代码后打开链接:http://127.0.0.1:5000
    1675513772257.png
  • 将127.0.0.1:5000输入到postman里面执行:
    1675513335074.png
  • 另外在代码里看到/hello,也可以输入执行查看结果:
    1675513837370.png

1675514350680.png

3. postman发送post请求

1675517681633.png

import pymysql
from flask import Flask,request

# 这里是mysql的基本连接信息
conn = pymysql.connect(
    host="192.168.1.116",
    user="root",
    password="123",
    database="nydb1",
    charset="utf8"
)


cursor = conn.cursor()


app = Flask(__name__)

@app.route("/")
def hello_world():

    sel = "select * from school"
    result = cursor.execute(sql)
    # 得到查询后的真正的结果
    r = cursor.fetchall()
    print(r)
    return str(r)


@app.route("/mypost",methods=["post"])
def my_post():
    return "post request"

@app.route("/mypost1",methods=["post"])
def my_post1():
    # 表单数据类型
    username =request.form["username"]
    sex = request.form["sex"]
    print(username)
    print(sex)
    return "post request" + username + "::" + sex




@app.route("/mypost1",methods=["post"])
def my_post2():
    # json数据类型
    request_data =request.get_json()
    sex = request.form["sex"]
    print(request_data)
    print(request_data["user"])
    return "post request" + str(request_data)

@app.route("/mypost",methods=["post"])
def my_post():
    return "post request"

@app.route("/mypost1",methods=["post"])
def my_post1():
    # 表单数据类型
    username =request.form["username"]
    sex = request.form["sex"]
    print(username)
    print(sex)
    return "post request" + username + "::" + sex




@app.route("/mypost2",methods=["post"])
def my_post2():
    # json数据类型
    request_data =request.get_json()
    sex = request.form["sex"]
    print(request_data)
    print(request_data["user"])
    return "post request" + str(request_data)

if __name__ == "__main__":
    app.run()

d890d6c407df7a7742a4c02da0a3645.png

6a627178280564d6c7b2f899cce1e9c.png

  • 并在python里打印出
    1675518002395.png
posted @ 2023-03-20 10:45  孙凯玉  阅读(19)  评论(0编辑  收藏  举报