This chapter will introduce to you what http is, what are the http request methods and transmission data types? It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
What is HTTP?
The full name of http (HyperText Transfer Protocol) is a set of rules for computers to communicate through the network.
http request method:
1. GET, get resources by requesting URI
2. POST, used to add new content
3. PUT is used to modify a certain content
4. DELETE, delete a certain content
5. PATCH, change some documents
get request
General data is passed in the URL, params: data
Example:
Request URL:http://api.anjianba.cn/api/Training/Query
or:
Request URL:http://api.anjianba.cn/api/Training/Query/23
{ name:"Myname", { types:[1,3], forms:[2,5] } }
If more complex data is passed, Query String Parameters, the background does not like to process this kind of data
After normal processing:
Request URL:http://api.anjianba.cn/api/Training/Query?planName=&startTime=&endTime=&types[]=1&types[]=3
Need this form:
Request URL:http://api.anjianba.cn/api/Training/Query?planName=&startTime=&endTime=&types=1&types=3
It is set in jQuery traditional:true, can be converted to the above data type.
axios config settings:
get(url, data = {}, options = {}) { let config = { params: data, headers: {、、、}, { 'paramsSerializer': function(params) { return qs.stringify(params, { indices: false }) // return qs.stringify(params, { arrayFormat: "repeat" }) }, ...options } return new Promise((resolve, reject) => { axios.get(url, config) .then(response => { resolve(response.data); }) .catch((error) => { reject(error); }) }) }
post, put, delet request
Submit this complex type of data:
{ name:"Myname", { types:[1,3], forms:[2,5] } }
The general data submission type is json:
The corresponding data declaration type: 'Content-Type':'application/json'
Serialization: JSON.stringify(data) json string
There is also the FormData type:
corresponding Data declaration type: 'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8'
Serialization: qs.stringify(data) ids[ ]=27&ids[]=26 ==> ids[0]=27&ids[1]=2
The above is the detailed content of What is http, what are the http request methods and data types passed?. For more information, please follow other related articles on the PHP Chinese website!