TPC/IP Protocol is a Transport layer protocol, which mainly solves how data is transmitted in the network, and HTTP is the application layer protocol, which mainly solves how to wrap the data. regarding the relationship between TCP/IP and HTTP protocol, the network has a relatively easy to understand: "When we transmit data, we can only use the (Transport Layer) TCP/IP protocol, but in that case, if there is no application layer, it will not be able to identify the data content, if you want to make the transmitted data meaningful, You must use the Application layer protocol, there are many application layer protocols, such as HTTP, FTP, Telnet, etc., you can also define the application layer protocol. The web uses the HTTP protocol as an application-layer protocol to encapsulate HTTP text information and then send it to the network using TCP/IP as the Transport layer protocol. ”
The term TCP/IP stands for Transmission Control Protocol/Internet Protocol, which refers to a series of protocols. "IP" represents an Internet protocol in which TCP and UDP use the protocol to transfer packets from one network to another network. Put
IP imagined as a highway, it allows other protocols to travel on it and find the exits of other computers.
TCP and UDP are "trucks" on highways, and the goods they carry are like HTTP, File Transfer Protocol FTP and so on. You should be able to understand that TCP and UDP are the transport layer protocols used by FTP,HTTP and SMTP. Although both TCP and UDP are used to transmit other protocols, they have a significant difference: TCP provides guaranteed data transfer, and UDP does not. This means that TCP has a special mechanism to ensure that data is safe from one endpoint to another without error, and UDP does not provide any such assurance. HTTP (Hypertext Transfer Protocol) is a protocol that leverages TCP to transfer information between two computers, typically Web servers and clients. The client initiates an HTTP request to the Web server using a Web browser, and the Web server sends the requested information to the client.
The following diagram attempts to show the location of the 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 |
such as XDR, ASN.1, SMB, AFP, NCP |
5 |
Session Layer |
For example ASAP, TLS, SSH, ISO 8327/ccitt x.225, RPC, NetBIOS, ASP, Winsock, BSD sockets |
4 |
Transport Layer |
such as TCP, UDP, RTP, SCTP, SPX, ATP, IL |
3 |
Network layer |
such as IP, ICMP, IGMP, IPX, BGP, OSPF, RIP, IGRP, EIGRP, ARP, RARP, x. |
2 |
Data Link Layer |
such as Ethernet, Token Ring, HDLC, Frame Relay, ISDN, ATM, IEEE 802.11, FDDI, PPP |
1 |
Physical Layer |
such as line, radio, optical fiber, homing pigeon |
1. Several important concepts of HTTP protocol
1. Connection (Connection): The actual circulation of a transport layer, which is built between two applications that communicate with one another.
2. Message: The basic unit of HTTP communication, including a structured eight-tuple sequence and transmission via a connection.
3. Request: A request from the client to the server includes the method that is applied to the resource, the identifier of the resource, and the version number of the Protocol
4. Response (Response): A message returned from the server includes the version number of the HTTP protocol, the status of the request (for example, "succeeded" or "not Found"), and the MIME type of the document.
5. Resource (Resource): A network data object or service that is identified by a URI.
6. Entity: A special representation of a data resource or a reflection from a service resource, which may be surrounded by a request or response message. An entity includes entity header information and the entity's own content.
7. Client: An application that establishes a connection for the purpose of sending a request.
8. User Agent (useragent): Initializes a requested client. They are browsers, editors, or other user tools.
9. Server: An application that accepts a connection and returns information to the request.
10. Source Server (Originserver): is a server on which a given resource can reside or be created.
11. Proxy: An intermediary program that can act as a server or as a client to establish requests for other clients. Requests are either internally or passed to other servers through possible translations. An agent must interpret and overwrite it if possible before sending the request information.
Proxies are often used as portals through the firewall's client side, and proxies can be used as a help app to handle requests that are not completed by the user agent through the protocol.
12. Gateway: A server that acts as an intermediary for other servers. Unlike the proxy, the gateway accepts the request as if it were the source server for the requested resource, and the requesting client is unaware that it is dealing with the gateway.
Gateways are often used as server-side portals through firewalls, and gateways can be used as a protocol translator to access resources stored in non-HTTP systems.
13. Channel (tunnel): is a broker that acts as a two connection relay. Once activated, the channel is considered not to be an HTTP communication, although the channel may be initialized by an HTTP request. The channel disappears when both ends of the relayed connection are closed. A channel is often used when a portal must exist or the intermediary (intermediary) cannot interpret the relay's traffic.
14. Cache: Local storage of the reaction information.
2. Sending the request
After a connection is opened, the client sends the request message to the server's dwell port to complete the request action.
The format of the http/1.0 request message is:
Request message = Request Line (General Information | request Header | entity header) crlf[entity content]
Request line = Method Request URL http version number CRLF
Method =get| head| Post| extension methods
U R l= protocol name + host name + directory and file name
The methods in the request line describe the actions that should be performed in the specified resource, and the commonly used methods are, and post. The result of a different request object corresponding to get is different, and the corresponding relationship is as follows:
Result of Object get
Contents of the File file
Program execution results of the program
Database query Query Results
HEAD?? Requires the server to look up the meta information of an object, not the object itself.
POST?? Data is transferred from the client to the server, and the Post method is used when the server and CGI are required to do further processing. Post is primarily used to send the contents of a form in HTML text to be processed by the CGI program.
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 called meta-information, Information, the use of meta-information can be used to achieve conditional requests or responses.
Request header?? Tell the server how to interpret the request, mainly including the type of data that the user can accept, the compression method, and the language.
Solid head?? Entity information type, length, compression method, last modification time, data validity period, and so on.
Entity?? Requests or answers the object itself.
3. Send a response
The server sends a response message to the client after it has finished processing the client's request.
The response message format for http/1.0 is as follows:
Response message = Status line (General Information Header | response header | entity header) crlf(entity content)
Status line =http version number status code reason narration
Status codes represent response types
1XX reserved
2XX indicates that the request was successfully received by
3XX request further refinement of requests for completion of customer requests
4XX Customer Error
5XX Server Error
The response header information includes the service program name, notifies the client that the requested URL requires authentication, and when the requested resource is available.
4. Close the connection
Both client and server can end TCP/IP conversations by closing sockets
TCP/UDP HTTP