Flask receives post request Request Paylod parameters

Today, when I wrote the back-end code, I couldn't get the parameters passed by the front-end. Why did the post request not get the parameters in the normal way?

Front-end vue
back-end flask

Back-end code

@app.route('/planFile', methods=['POST'])
def downloadPlanData():
    planId = request.from.get('planId')  # 正常接受post请求参数的一种方式

FIG reasons
Figure one
noted above figure is post request parameter passing Request Payloadmode so used request.from.get('planId')to acquire not only the parameters are acquired in the following figure Form Dataonly mode can receive parameters
Insert picture description here

So use Request Payloadin the end how to receive the parameters when it passed by

Solution

Two ways

  1. Front-end to resolve (the idea is to Request Payloadfashion into Form Dataa limited ability to change the way Zenmo not answer here)

  2. The rear end to solve the
    flask used request.json.get('planId')may receive parameters

    @app.route('/planFile', methods=['POST'])
    def downloadPlanData():
        planId = request.json.get('planId')
    

The overall reason is that the front-end and back-end methods of passing and receiving parameters are not unified. The
solution is to unify the method of parameter transfer.

Guess you like

Origin blog.csdn.net/weixin_41822224/article/details/107632445