flask使用post传递参数

#后端代码

from flask import Flask,request
import json

app = Flask(__name__)

@app.route('/loginsss',methods=['GET','POST'])
def hello_world():
    # numb = int(request.args.get('numb'))
    # numb += 1
    # return str(numb)
    if request.method == 'POST':
        data = request.get_data()
        data = json.loads(data)
        numb = int(data.get('numb'))
        numb += 1
        return str(numb)
if __name__ == '__main__':
    app.run(debug=True)

#前段代码

import requests
import json
url = 'http://127.0.0.1:5000/loginsss'
# params = {
#     'numb':'4',
# }
data = {
    'numb':'4'
}
res = requests.post(url=url,data=json.dumps(data))
print(res.text)

你可能感兴趣的:(flask使用post传递参数)