What is HTTP protocol

一个新手
Release: 2017-09-19 10:06:09
Original
4092 people have browsed it

A brief introduction to the HTTP protocol

The HTTP protocol is a hypertext transfer protocol, which is a communication protocol based on TCP/IP for data transmission

Features:
1. Simple and fast , when the client initiates a request to the server, it only needs to transmit the request method and path. Commonly used request methods include POST, GET, etc. Each method specifies a different type of contact between the client and the server. Because the HTTP protocol is simple, the communication speed is fast
2. Flexible: any type of data object can be transmitted. The transmission type is marked by Content-Type
3. No connection: Limit each connection to only process one request. After the server processes the client's request, it will disconnect after receiving the client's response
4. Stateless: HTTP is a stateless protocol. Stateless means that the protocol has no memory ability for transaction processing. The lack of status means that if the previous information is needed for subsequent processing, it must be retransmitted, which may increase the amount of data transmitted per connection. On the other hand, when the server does not need other information, its response will be very fast
5. Supports B/S and C/S modes

URL

URL is a uniform resource identifier used by HTTP to transmit data and establish connections. URL is a special type of URI, the full name is UniformResourceLocator, and the Chinese name is Uniform Resource Locator. The URL contains the following parts:
For example: https://baike.baidu.com:8080/item/url/110640 ?fr=aladdin
1. Protocol/mode part: It tells the browser how to handle the file to be opened. The most commonly used mode is the Hypertext Transfer Protocol (HTTP), which is used to access the Internet. Other protocols are as follows:
http——Hypertext Transfer Protocol resources
https - Hypertext Transfer Protocol delivered using Secure Sockets Layer
ftp——File Transfer Protocol
mailto——email address
ldap——Lightweight Directory Access Protocol Search
file - a file shared on a local computer or online
News——Usenet News Group
gopher——Gopher protocol
telnet——Telnet protocol
In the above example, the protocol part is https
2. Domain name part: The above domain name is: baike.baidu.com
3. Port part: What follows the domain name is is the port number. Use: to separate the port from the domain name. The port is not a necessary part of a URL. If the port number is omitted, the default port will be used
4. The file name part: /item/url/110640
5 . Parameter part: fr=aladdin, that is,

Request


after the question mark. The HTTP request message Request mainly consists of the following parts:
* Request line: Request method | URL | Protocol version
* Request header: The request header contains a lot of useful information about the client environment and the request body
* Request body: There is a blank line between the request header and the request body. This The line is very important, it indicates that the request header has ended, and what follows is the request body. The request body can contain query string information submitted by the customer

Response

HTTP response message Response consists of the following parts:
* Status line: Protocol version | Status code | Status Message
* Response header: Date, Content-Type, etc.
* Response text: Server-side return data

Status code

The status code consists of three digits, the first Numbers define the category of the response
* 1xx: Indication message, indicating that the request has been received, continue processing
* 2xx: Success, indicating that the request has been successfully received
* 3xx: Redirect, indicating that the request will be made at night Further operations are required
* 4xx: Client error, indicating that the request has a syntax error or cannot be implemented
* 5xx: Server error, indicating that the server failed to implement a legal request

Common status Code:

200 - ok - 请求成功400 - Bad Request - 客户端请求有语法错误,不能被服务器理解401 - Unauthorized - 请求未经授权403 - Forbidden - 服务器收到请求,但是拒绝提供服务404 - Not Found - 请求资源不存在500 - Internal Server Error - 内部服务器错误503 - Server Unavaliable - 服务器不可用
Copy after login

Request method

HTTP 1.0 定义了三种请求方法 :GET、POST、HEAD
HTTP 1.1 新增了五种请求方法 :OPTIONS、PUT、DELETE、TRACE、CONNECT
Copy after login
GET - 请求指定的页面信息,并返回实体主体
HEAD - 类似于GET请求,但是返回的只有报头
POST - 向指定的资源提交数据进行处理请求
PUT - 从客户端向服务器传送的数据取代指定文件的内容DELETE - 请求服务器删除指定的页面
CONNECT - HTTP/1.1协议中预留给能够将连接改为管道方式的代理服务器。OPTIONS - 允许客户端查看服务器性能
TRACE - 回显服务器收到的请求,主要用于测试或诊断。
Copy after login

The difference between GET and POST

  1. Data submission: GET request data will be placed after the URL, using & number to connect, but the POST request data will be placed in the HTTP packet

  2. Transmission data size: Since general browsers have restrictions on the length of the URL, GET is used to request the data There will be a size limit, but POST puts the data in the package, that is, there is no size limit

  3. Security: GET submits the data in the URL and can be cached to return the data

Note:
1. The HTTP protocol does not limit the size of transmitted data, and the HTTP protocol specification does not limit the length of the URL.
2. HTTP’s GET, POST, and SOAP protocols all run on http

(1) GET: The request parameters are appended to the URL as a sequence of key/value pairs (query string) The length of the
query string is limited by web browsers and web servers (such as IE supports up to 2048 characters), which is not suitable for transmitting large data sets. At the same time, it is very unsafe

(2) POST: The request parameters are transmitted in a different part of the http header (named entity body). This part is used to transmit form information, so Content-type must be set to: application/x-www- form-urlencoded. Post is designed to support user fields on web forms, and its parameters are also transmitted as key/value pairs.
But: it does not support complex data types because post does not define the semantics and rules for transmitting data structures.

(3) SOAP: It is a special version of http post, following a special xml message format
Content-type is set to: text/xml Any data can be xmlized.

The HTTP protocol defines many methods of interacting with the server, the most basic of which are GET, POST, PUT, and DELETE. A URL address is used to describe a resource on the network, and in HTTP GET, POST, PUT, and DELETE correspond to the four operations of checking, modifying, adding, and deleting this resource. Our most common ones are GET and POST. GET is generally used to obtain/query resource information, while POST is generally used to update resource information.

The above is the detailed content of What is HTTP protocol. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!