目录
1. postman介绍与安装
2. postman发送get请求
3. postman发送post请求
1. postman介绍与安装
- 安装网址:Postman
- 安装教程:留言找我要即可
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
- 将127.0.0.1:5000输入到postman里面执行:
- 另外在代码里看到/hello,也可以输入执行查看结果:
3. postman发送post请求
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()
- 并在python里打印出
以下是我收集到的比较好的学习教程资源,虽然不是什么很值钱的东西,如果你刚好需要,可以评论区,留言【777】直接拿走就好了
各位想获取资料的朋友请点赞 + 评论 + 收藏,三连!
三连之后我会在评论区挨个私信发给你们~