What is http, what are the http request methods and data types passed?

青灯夜游
Release: 2018-09-19 09:35:17
Original
3497 people have browsed it

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
Copy after login

or:

Request URL:http://api.anjianba.cn/api/Training/Query/23
Copy after login
{    name:"Myname",
    {
    types:[1,3],
    forms:[2,5]
    }
}
Copy after login
Copy after login

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
Copy after login

Need this form:

Request URL:http://api.anjianba.cn/api/Training/Query?planName=&startTime=&endTime=&types=1&types=3
Copy after login

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);
				})
		})
	}
Copy after login

What is http, what are the http request methods and data types passed?

post, put, delet request

Submit this complex type of data:

{    name:"Myname",
    {
    types:[1,3],
    forms:[2,5]
    }
}
Copy after login
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template