What Java EE needs to understand: 1. Illustration of Http protocol and JavaEE Diagram

Source: Internet
Author: User

What Java EE needs to understand: 1. Illustration of Http protocol and JavaEE Diagram

Writer: BYSocket)

Weibo: BYSocket

Bean flap: BYSocket

FaceBook: BYSocket

Twitter: BYSocket

The bricklayer remembers to have a Session with Zuo Yunlong [blog park] during the last chat. What I understood at the time was that the cloud was in the fog. Let's start by understanding the Http protocol.

I. Technical Foundation and overview

Q: What is HTTP?
A: HTTP is a standard TCP protocol for client and server requests and responses. In fact, it is built on TCP.

When we open the Baidu webpage, it is like this:

Https://www.baidu.com

S is added. In fact, S indicates TLS and SSL. I will not explain it here, so the technical cornerstone of HTTP:

What about HTTP? HyperText Transfer Protocol (HTTP) is the Transfer Protocol used by servers to transmit data to the client browser. On the Web, servers and clients use the HTTP protocol for communication sessions. With the idea of OOP, we can conclude that the session structure is a simple request/response sequence, that is, the browser sends a request and the server responds.

2. gain an in-depth understanding of the technical foundation and workflow

Since HTTP is a TCP protocol based on the transport layer, TCP is a connection-oriented end-to-end protocol. Therefore, before using the HTTP protocol for transmission, a TCP connection is first established, which is the "three-way handshake" of the TCP connection process ".

On the Web, the reason why HTTP uses TCP rather than UDP is that a webpage must transmit a lot of data and ensure its integrity. The TCP protocol provides transmission control to organize data and correct errors in sequence.

An HTTP operation is called a transaction. The procedure can be divided into four steps:

1. A connection must be established between the client and the server. (For example, for a hyperlink, HTTP starts .)

2. Send a request after the connection is established.

3. The server responds to the request.

4. The information returned by the client receiving server is displayed on the user's display screen through a browser, and the client is disconnected from the server.

Establishing a connection is actually based on a TCP connection. The core work process (that is, the connection process is omitted) is illustrated as follows:

Iii. Explanation of HTTP packets during work

An HTTP packet consists of a request from the client to the server and a response from the server to the client.

1. Request Message format:

Request Line

Common Information Header

Request Header

Entity Header

(Empty rows)

Message Body

, The message content sent when requesting an article in my blog:

Detailed description of request packets:

1. Request Line

Method Field + URL + Http Protocol version

2. General information Header

Cache-Control header field: Specifies the Cache mechanism for requests and responses.

Keep-alive is the continuous validity of its connection. [The following Baidu example will be verified]

3. Request Header

Host Header domain.

Referer header field: allows the client to specify the resource address of the request URL.

User-Agent header field: request User information. [We can see the kernel information of some client browsers]

4. Message Subject

In general, the request subject must have the request parameters.

Ii. Response Message format:

Status line

Common Information Header

Response Header

Entity Header

(Empty rows)

Message Body

Is the response content of this blog:

Detailed explanation of the Response Message:

1. Status line

Text description of HTTP Protocol version + status code

For example, 200 indicates that the request is successful]

2. General information Header

Keep-alive is the continuous validity of its connection. [The following Baidu example will be verified]

Date header field: time Description

3. Response Header

Server header: The software information of the original Server that processes the request.

4. Object Header

Content-Type header: the media Type of the recipient object. (This also indicates the subject of your message .)

(Empty rows)

5. Message Subject

Here is the HTML response page, which can be viewed in response on the tab page.

A simple request/response is complete.

Iii. Supplement of HTTP protocol knowledge

Request Message:

Request Line-Request Method

GET Request to GET the resource identified by Request-URI
POST attaches new data to the resource identified by Request-URI
HEAD Request to obtain the Response Message Header of the resource identified by Request-URI
The PUT Request server stores a resource and uses Request-URI as its identifier.
The DELETE Request server deletes the resource identified by Request-URI.
TRACE Request information received by the server for testing or diagnosis
CONNECT reserved for future use
OPTIONS requests query server performance, or query resource-related OPTIONS and requirements

Response Message:

Response line-status code

1xx: indicates that the request has been received and continues to be processed.
2xx: Success-indicates that the request has been successfully received, understood, and accepted
3xx: Redirection-further operations are required to complete the request
4xx: client error-the request has a syntax error or the request cannot be implemented
5xx: Server Error-the server fails to fulfill valid requests

Common Status Codes

200 OK

The request is successful (followed by the response document to the GET and POST requests .)

304 Not Modified

The document was not modified as expected. The client has a buffered document and sends a conditional request (generally, the If-Modified-Since header is provided to indicate that the customer only wants to update the document on a specified date ). The server tells the customer that the original buffer documentation can still be used.

404 Not Found

The server cannot find the requested page.

500 Internal Server Error

The request has not been completed. Unpredictable server conditions.

For example, in 304, when the browser opened Baidu for the first time ,:

Refresh:

The 304 above proves that

1. 304 status code: some images and js files are cached on the local client. After another request, cached files can be used.

2. The above HTTP request only relies on one TCP connection, which is called a persistent connection.

4. Web application framework or specifications on the HTTP protocol

JavaEE users will be aware of Servlet specifications. Web application containers all implement HTTP objects, namely, request and response objects. For example, the javax. servlet. http. HttpServletResponse object must have a description of the status code,

As for how to use them, wait for a series of articles.

V. Summary

Looking back at the full text, the HTTP protocol is actually the same as our conversation, and the language is the protocol. Therefore, you can understand the following aspects of HTTP:

1. What is used for HTTP Communication?

2. How to communicate through HTTP

Writer: BYSocket)

Weibo: BYSocket

Bean flap: BYSocket

FaceBook: BYSocket

Twitter: BYSocket

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.