Send a request using the post axios, JSON data to the type of form

Typically the front end by a POST request submitted to the server-side data format 4, respectively, is "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 JSON string.

image
In the console see the data is this:
image

Sometimes the background will often get parameters, it is possible to receive because of the type of background for the form, the form needs to Form data to parse correctly, the front end need to change the format at the time of the last pass

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

After setting the Content-type when the see the request into a application / x-www-form format, which is not finished, it needs qs. While saying axios built, but every time I myself once installed

The first step: introducing axios ps
image
Step 2: Use qs conversion
image
look after it requested data format becomes a matter like this:
image

Guess you like

Origin www.cnblogs.com/zly430/p/11414260.html