Params and the difference between the data and the data transmission request params of the Axios Axios

Axios distinction data transmission request and the params

 https://www.cnblogs.com/cwzqianduan/p/8675356.html(copy
When using axios, noticed configuration options include both params and data, I thought they were the same, but in reality not. 

Because params url string is added to the request in, for get request.

Is added to the request and the data body (body) is used to post requests.

For example, the following get request:
Axios ({
Method: "get",
URL: " http://www.tuling123.com/openapi/api?key=20ff1803ff65429b809a310653c9daac ",
the params: {
info: "Xi Weather"
}
} )
If we modify the data params, it is clearly not the request was successful, because the get request data this option does not exist.

1, HTTP request process, get request: url form parameter is attached to the rear in the form name = value of & name1 = value1;

2, post request: form parameter in the request body, is the form name = value & name1 = value1 of the body of the request.
When the POST form request is submitted, Content-Type using the application / x-www-form- urlencoded, using native AJAX POST request If no request header RequestHeader, Content-Type is used by default text / plain; charset = UTF -8.
Form in the html defaults Content-type: Content-type: application / x-www-form-urlencoded
If you are using ajax request, way request payload lead to arguments appear in the request header is changed, then the solution is:
headers: { 'Content-Type': ' application / x-www-form-urlencoded'}
or using ajax provided:
$ .ajaxSetup ({contentType: 'file application / X-WWW-form-urlencoded'});
Thus, problems can solve.
When using axios, noticed configuration options include both params and data, I thought they were the same, but in reality not. 

Because params url string is added to the request in, for get request.

Is added to the request and the data body (body) is used to post requests.

For example, the following get request:
Axios ({
Method: "get",
URL: " http://www.tuling123.com/openapi/api?key=20ff1803ff65429b809a310653c9daac ",
the params: {
info: "Xi Weather"
}
} )
If we modify the data params, it is clearly not the request was successful, because the get request data this option does not exist.

1, HTTP request process, get request: url form parameter is attached to the rear in the form name = value of & name1 = value1;

2, post request: form parameter in the request body, is the form name = value & name1 = value1 of the body of the request.
When the POST form request is submitted, Content-Type using the application / x-www-form- urlencoded, using native AJAX POST request If no request header RequestHeader, Content-Type is used by default text / plain; charset = UTF -8.
Form in the html defaults Content-type: Content-type: application / x-www-form-urlencoded
If you are using ajax request, way request payload lead to arguments appear in the request header is changed, then the solution is:
headers: { 'Content-Type': ' application / x-www-form-urlencoded'}
or using ajax provided:
$ .ajaxSetup ({contentType: 'file application / X-WWW-form-urlencoded'});
Thus, problems can solve.

Guess you like

Origin www.cnblogs.com/dianzan/p/11314261.html