request.json

2019-03-08  本文已影响0人  wnl

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
上一篇下一篇

猜你喜欢

热点阅读