python Flask reqest 测试

得意时要看淡,失意时要看开。不论得意失意,切莫大意;不论成功失败,切莫止步。志得意满时,需要的是淡然,给自己留一条退路;失意落魄时,需要的是泰然,给自己觅一条出路python Flask reqest 测试,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

server.py

# !/usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
@author: JHC 
@license: None
@contact: JHC000abc@gmail.com
@file: server.py
@time: 2022/09/11/ 21:51
@desc:
"""
import json
from flask import Flask, request

app = Flask(__name__)

@app.route("/")
def test():
    return "Hello world !"

@app.route("/say/<name>")
def say(name):
    return f"say{name}"


@app.route("/post",methods=["POST"])
def post_test():
    data_json = json.loads(request.data)
    username = data_json["username"]
    passwd = data_json["passwd"]
    date = data_json["date"]
    secret = data_json["secret"]
    code_lis = data_json["secret"]["Authentication authorization code"]
    print(username,passwd)
    print(date)
    print(secret)
    print(code_lis)
    return secret

if __name__ == '__main__':
    app.run(debug=True)

requests_test.py

# !/usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
@author: JHC 
@license: None
@contact: JHC000abc@gmail.com
@file: req_test.py
@time: 2022/09/11/ 22:23
@desc:
"""
import datetime
import requests


url = "http://127.0.0.1:5000/post"
data = {
    "username": "user01",
    "passwd":"123456",
    "date":datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
    "secret": {
        "Create time":"2022-09-11 22:47:53",
        "Authorized unit":"bj powernode",
        "Expiration":{
            "Year":2023,
            "Month":12,
            "Day":22,
            "Hours":12,
            "Minutes":12,
            "Seconds":30
        },
        "Authentication authorization code":["4a8046ca-cdce-4325-9016-7b0fa0d967ed","fda22554-1278-3f4e-b7b4-6f8f78bac9ef"]
    }
}

res = requests.post(url,json=data)
print(res.text)

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/156897.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!