【发布时间】:2017-12-01 07:17:26
【问题描述】:
问题:
我想将带有-F 选项的文件以及带有-d 的json 数据发送到烧瓶路由。但只有我可以实现。
我试过的代码。
curl -X POST -H "Content-Type: application/json" -d '{"username":"xyz","password":"xyz"}' http://192.168.150.113/test
烧瓶代码:
@app.route('/test',methods = ['GET', 'POST'])
def test():
if request.method == 'POST':
data = request.data
data = json.loads(data)
return 'success'
只有文件:
curl -X POST -F file=@sample.txt http://192.168.150.113/test
@app.route('/process' , methods = ['GET', 'POST'])
def process():
if request.method == 'POST':
f = request.files['file']
if f:
try:
filename = secure_filename(f.filename)
f.save( os.path.join(app.config['UPLOAD_FOLDER'], filename ))
return 'success'
但是在不发送单独请求的情况下,我想结合这两个 POST 请求并使用烧瓶处理..
有什么办法可以做到吗?
【问题讨论】:
标签: php python json curl flask