The HTTP network protocol of TCP/IP protocol (i)

Source: Internet
Author: User
Tags ftp protocol

Part1. The most familiar strangers

Compared with the TCP/UDP protocol, the HTTP protocol may be more familiar, as everyone can see the http://xxx.com word everywhere. But, really

The students who are aware of the HTTP protocol may be just a few, and many people don't even know what "404" means. And this article, it is to let everyone more in-depth understanding

Next to the most familiar stranger.

The status of Part2.http in the lakes and rivers

As we all know, the Internet Four Layer network model (also known as TCP/IP four layer model) includes data link layer, network layer, Transport layer and application layer. The most famous protocol of the network layer is the IP protocol, the most famous protocol of the transport layer is the TCP protocol and the UDP protocol, and the application layer has many protocols, such as FTP protocol, telent protocol, TFTP protocol, POP protocol, SMTP protocol, DNS protocol, SNMP protocol, And of course the main character of this article is the HTTP protocol. If the TCP/UDP/IP deal counts as a hero behind the scenes, it is no exaggeration to say that the HTTP protocol is the star of the biggest wrist.

Part3.http about how it works.

HTTP, which conforms to the Client/sever model, is always the client to initiate the request. The whole process can be easily divided into four steps:

(1) The client initiates the request, and the server side completes the "TCP Three handshake";

(2) The client sends an "HTTP request message" to the server side;

(3) The server sends an "HTTP response message" to the client after the internal processing is completed;

(4) Client and server end "TCP Four break Up".

The HTTP protocol itself is a stateless protocol, meaning that each HTTP message does not depend on the status of the preceding message.

How part4.http URLs are represented

The first reason to tell the URL is because this knowledge point is frequently used later in this article.

The URLs in the HTTP protocol are primarily used to locate server-side resources. Let's look at its syntax definition:


http://http[:p Ort][path]

which

http://Indicates that the protocol we are using is the HTTPS protocol;

The host represents an available domain name or IP address;

Port is optional, indicating the port number to be requested, 80 by default

Path is optional, which indicates the path (also called URI) of the resource to be requested, by default/


What does the part5.http request look like?

Let's take a look at what a typical HTTP request message looks like:

(We use the/* * * * * * * * * * * In the request, let everyone better understand the meaning of each line of statements)


/* The first line is called the request line, and the other lines are called the Head row (header) */


/ * The request line consists of three fields: Method field, Uri field, HTTP version field * /

/* The request line for this example is to do one thing: with the HTTP protocol 1.1 version, using the Get method, to the server-side

Apply for/path/to/page.html resources */

Get/path/to/page.html http/1.1


/* Below all belong to the head line */


/* Host is used to specify the server-side host bit to be requested roclinux.cn */

Host:roclinux.cn


/ * Connection:close is to tell the server side that my client does not want to use persistent connection, please server side to complete this request response after closing

This connection. Although the HTTP1.1 version that supports persistent connections is used in this message request, the client still does not want to use persistent connections */

Connection:close


/ * user-agent domain is used to specify who the current request message is generated, generally speaking, this is usually set up in the browser used by the user

Type. Do not underestimate this domain, some intentions of the webmaster, will be through the domain to identify customers, and to different customers show different versions of resources! */

user-agent:mozilla/4.0


/ * accept-language domain, then the client and the server said "If you have my application of the resources of the Chinese version, then the Chinese version to me;"

If you don't have a Chinese version, just give me your default language version. " */

Accept-language:zh-cn


/ * Look here, look here! Perhaps no one noticed here, there is a blank line, and there must be this empty line. This is the HTTP protocol's hard

Rules, don't forget oh * *


Below, with a picture I have carefully drawn, to illustrate the format of the HTTP protocol request message:


From the above figure, it should be clear to see the specific format of the request message.

What are the methods in the PART6.HTTP request message

There are a lot of HTTP request methods, we take a look at:

Get method: Request a resource

Post method: Request a resource with some data attached

Head method: Request a response message header for a resource

Put method: Upload a resource

Delete method: Deletes a resource

Track method: Allow the server to echo Request messages for debugging and troubleshooting

OPTIONS: Request Server Performance Information

CONNECT: Reserved for the proxy server

Part7. How to respond to HTTP requests

After knowing the format of the request message, do you want to know how the HTTP protocol responds to the request message, and we look at a typical response message:

/* A response message, which typically consists of three parts, the state line, the head row, the Subsidiary Body */


/*  the first line is the status line, which includes three fields: Version field, status Code field, reason phrase field  */

/* In this example, the HTTP protocol response message is intended to mean that the server is using the HTTP protocol 1.1 version and has found the client

And will send the response message to the client, the whole process is normal */

http/1.1 OK


/* The server side will not hold this connection, but will disconnect the connection after replying to the response message */

Connection:close


/* Here's the point at which this response message was sent out. */

Date:thu, OCT 2005 03:17:33 GMT


/* Server domain indicates that this response message was issued by an Apache server on a Unix-like operating system and that the Apache version is 2.0.54 */

server:apache/2.0.54 (Unix)


/* For recording the last modification time of the data stored in the response message */

last-modified:mon,22 June 1998 09;23;24 GMT


/* Indicates the number of bytes in the data section, which is the unit byte */

content-length:6821


/* Indicates that the contained data is HTML text content */

Content-type:text/html


*/* Look here, still have to see here, and request message similar, here also has a blank line, can't save Oh */


/* Here is the actual response data */

(Data data Data ...). )


Below, we also look at the protocol format of the response message:


Part8. Talk about the HTTP status code

When it comes to HTTP response messages, you have to mention HTTP status codes. I believe that after reading this section, you will be very clear about what the 404 represents.

The status code is only three bits in total, and the first one represents the status category, which is divided into five types, and we'll look at it in turn:

1XX: Is the progress notification class status, meaning "request I have received, or your request I am processing";
2XX: Said "Your request I have successfully processed";
3xx: That is, redirect, that is, the server tells the client, "you want the resources to move, you go to some place to find him again";
4XX: There are some errors in the response message sent by the client, such as syntax error or the requested resource does not exist;
5XX: There are some problems on the server side that cannot be processed to complete your request.

In fact, often the status code is not much, we put the common list in this:

OK: The client request is successful, the client wants something in the response message;
301 Moved Permanently: client Ah, you want to request the resources have been permanently moved, I put his new address in the location of the head domain;
302 Moved temporarily: client Ah, you want to request the resources temporarily to go somewhere else, I put his position in the location of the head of the domain, you can first go there to find him, but he should be back to his own home;
304 Not Modified: client Ah, the resource you want to request has not changed since the last time you requested it, I think you should have this resource already, so in the data part of the response message I also did not put this resource.
The bad request: the client sent a message with a syntax error, the server is really not understand;
401 Unauthorized: The client sends a request that is not a legitimate source of the request, that is, the client is not authorized;
403 Forbidden: The server side has successfully received the client's request, but for some reason, the server refused to provide services to him;
404 Not Found: The client to request the resource does not exist, probably is the resource address is wrong;
Internal Server Error: Unfortunately, the server can not provide services to you, the server has an unpredictable problem inside;
502 Bad Gateway: client Hello, I am the proxy server requesting the message, the server that holds the resource has a problem sending me resources;
503 Server Unavailable: The server may be too busy now, temporarily unable to service you this client, perhaps later will recover.

The HTTP network protocol of TCP/IP protocol (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.