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

Source: Internet
Author: User

Typically, the front end submits data to the server via a POST request in 4 format, "application/x-www-form-urlencoded" format, "multipart/form-data" format, "Application/json" Format and "Text/xml" format. Often the most common is the "Application/json" format, which is the form of a JSON string.

The data you see in the console is this:

Sometimes the background needs form form of data in order to parse normally, so the front end needs to change the format when passing through. At first I thought it was to modify the Content-tyoe property, so I

Axios.defaults.headers = {    ' content-type ': ' application/x-www-form-urlencoded '}

When you see the request, the content-type becomes the application/x-www-form format, but the data does not change. After looking for a long time finally found the real method.

First step: Introduce Axios PS

Step two: Using the QS Conversion

Then look at the request data format as follows:

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.