美文网首页
request.json

request.json

作者: wnl | 来源:发表于2019-03-08 18:06 被阅读0次

    flask获取json数据,request.json,

    from flask import Flask,request

    app = Flask(__name__)

    @app.route('/register',methods=["POST"])

    def register():

    data = request.json

    print(data)

    return 'ok'

    if __name__ =='__main__':

    app.run(host='192.168.11.1',port=1234,debug=True)


    然后POST数据,使用requests

    import requests

    import json

    post_data = {"name":"hahaha","pass":"pass"}

    headers = {'Content-Type':'application/json;charset=UTF-8'}

    res=requests.post(url="http://192.168.11.1:1234/register",data=json.dumps(post_data),headers=headers)

    print(res.text)

    post-1 post-2

    相关文章

      网友评论

          本文标题:request.json

          本文链接:https://www.haomeiwen.com/subject/ioqdpqtx.html