The TPC/IP protocol is the transport layer protocol, which mainly addresses how data is transmitted over the network, while HTTP is the application layer protocol, which mainly addresses how to package data.The relationship between TCP/IP and HTTP is easy to understand:"When transmitting data, we can only use the (Transport Layer) TCP/IP protocol. However, without the application layer, we cannot identify the data content, to make the transmitted data meaningful, you must use the application layer protocol. There are many application layer protocols, such as HTTP, FTP, and telnet. You can also define the application layer protocol by yourself. The Web uses HTTP as the application layer protocol to encapsulate HTTP text information, and then uses TCP/IP as the transport layer protocol to send it to the network ."
The term TCP/IP stands for the Transmission Control Protocol/Internet Protocol, which refers to a series of protocols. "Ip" indicates the Internet Protocol. TCP and UDP use this Protocol to send packets from one network to another. Set
IP can be imagined as a highway It allows other protocols to drive on and find the exit of other computers.
TCP and UDP are "trucks" on the highway, and they carry goods like HTTP , File transfer protocol such as ftp. You should understand that TCP and UDP are transport layer protocols used for FTP, HTTP, and SMTP. Although both TCP and UDP are used to transmit other protocols, they have a significant difference: TCP provides guaranteed data transmission, while UDP does not. This means that TCP has a special mechanism to ensure data security from one endpoint to another without errors, while UDP does not provide any such guarantee. HTTP (Hypertext Transfer Protocol) is a protocol that uses TCP to transmit information between two computers (usually web servers and clients. The client uses a web browser to initiate an HTTP request to the Web server, and the Web server sends the requested information to the client.
The following chart tries to display the positions of different TCP/IP and other protocols in the original OSI model:
7 |
Application Layer |
Such as HTTP, SMTP, SNMP, FTP, telnet, sip, ssh, NFS, RTSP, XMPP, Whois, ENRP |
6 |
Presentation Layer |
For example, XDR, ASN.1, SMB, AFP, and NCP |
5 |
Session Layer |
Such as ASAP, TLS, ssh, ISO 8327/CCITT x.225, RPC, NETBIOS, ASP, WinSock, BSD sockets |
4 |
Transport Layer |
For example, TCP, UDP, RTP, sctp, SPX, ATP, and IL |
3 |
Network Layer |
For example, IP, ICMP, IGMP, IPX, BGP, OSPF, Rip, IGRP, VPN, ARP, RARP, and X.25 |
2 |
Data Link Layer |
Such as Ethernet, licensing ring, HDLc, frame relay, ISDN, ATM, IEEE 802.11, FDDI, PPP |
1 |
Physical Layer |
For example, line, radio, optical fiber, and pigeon |
1. Several important concepts of HTTP protocol
1. connection: the actual circulation of a transport layer, which is established in two applications of mutual communication. Program .
2. Message: The basic unit of HTTP Communication, including a structured sequence of eight-element groups and transmitted through connections.
3. Request: The request information from the client to the server includes the method, resource identifier, and Protocol version number applied to the resource.
4. Response: The information returned by an slave server includes the HTTP version number, the Request status (for example, "successful" or "not found"), and the MIME type of the document.
5. Resource: network data object or service identified by Uri.
6. entity: A special representation of a data resource or service resource, which may be enclosed in a request or response. An object includes object header information and object content.
7. Client: an application that establishes a connection to send a request.
8. useragent: the client that initializes a request. They are browsers, editors, or other user tools.
9. SERVER: an application that accepts connections and returns information for requests.
10. originserver: A server on which a given resource can reside or be created.
11. Proxy: An intermediate program that can act as a server or a client and create a request for other clients. Requests are transmitted to other servers through possible translation. A proxy must explain before sending the request information and rewrite it if possible.
A proxy is often used as a portal through a firewall client. A proxy can also be used as a help application to process requests that are not completed by a user proxy through a protocol.
12. Gateway: A server serving as the intermediate media of other servers. Different from the proxy, the gateway accepts the request as if it is the source server for the requested resource; the client sending the request does not realize that it is dealing with the gateway.
The gateway is often used as a portal for servers that use firewalls. The Gateway can also be used as a protocol translator to access resources stored in non-HTTP systems.
13. Tunnel: it is an intermediary program used as two connection relay. Once activated, the channel is considered not to belong to HTTP Communication, although the channel may be initialized by an HTTP request. When the two ends of the relay connection are closed, the channel disappears. The channel is frequently used when a portal must exist or intermediary cannot interpret the relay communication.
14. cache: Local Storage of response information.
2. Send a request
After a connection is opened, the client sends the request message to the server's Stop port to complete the request.
The format of the HTTP/1.0 request message is:
Request Message = request line (Common Information | Request Header | entity header) CRLF [entity content]
Request Line = method request url http Version Number CRLF
Method = GET | HEAD | post | Extension Method
U r l = protocol name + host name + directory and file name
The method description in the request line specifies the actions to be executed in the resource. Common methods include get, Head, and post. The get results of different request objects are different, and their relations are as follows:
Object get result
File Content
Program Execution result of the program
Database query results
Head ?? The server is required to search for the metadata of an object rather than the object itself.
Post ?? The post method is used when the server and CGI are required for further processing to transmit data from the client to the server. Post is mainly used to send Form Content in HTML text for CGI programs to process.
An example of a request is:
Gethttp: // networking.zju.edu.cn/zju/index.htmhttp/1.0 networking.zju.edu.cn/zju/index.htmhttp/1.0 header information is also known as metadata, which enables conditional requests or responses.
Request Header ?? Tell the server how to interpret the request, including the data types, compression methods, and languages that the user can accept.
Entity header ?? Object Information type, length, compression method, last modification time, data validity period, etc.
Entity ?? The request or response object itself.
3. Send Response
The server sends a Response Message to the client after processing the customer's request.
The Response Message format for HTTP/1.0 is as follows:
Response Message = Status line (Common Information header | response header | entity header) CRLF [entity content 〕
Status line = HTTP Version status code reason description
Status Code indicates the response type
1 × Reserved
2×× indicates that the request is successfully received.
3×× further refine the request to complete the request
4×× customer Error
5×× Server Error
The response header information includes the service program name, the URL that notifies the customer of the request to be authenticated, and the requested resource when it can be used.
4. Close the connection
Both the client and server can end the TCP/IP conversation by closing the socket.