Use the AXIOS to send a POST request to change the JSON data to the form type

Typically the front end submits the data format to the server side by the POST request. There are 4, named “Application / X-WWW-FORM-URLENCODED” format, “Multipart / Form-Data” format, “Application / JSON” format and ” TEXT / XML format. Usually the most common is “Application / JSON” format, that is, through the JSON string.

使用axios发送post请求,将JSON数据改为form类型的示例

The data seen in the console is this:

使用axios发送post请求,将JSON数据改为form类型的示例

Sometimes the background needs the form of form in form. Normal parsing, so the front end needs to modify the format when passing. I thought it was a modification of the Content-Tyoe property, so

 AXIOS.DEFAULTS.HEADERS = {'Content-Type': 'Application / X-WWW-FORM-URLENCODEDED '}   
After setting the content-type when the request is set to the Application / X-WWW-form format, but the data has not changed. Then I found a real way I finally found a real way.

Introduced AXIOS PS

Step 2: Use QS conversion 使用axios发送post请求,将JSON数据改为form类型的示例

After seeing the request data format becomes this:

使用axios发送post请求,将JSON数据改为form类型的示例

The above uses AXIOS to send a POST request, will json The sample changed to the form type is the total content of Xiaobian sharing to everyone. I hope I can give you a reference, and I hope that you will support Tumi Clouds.

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment