Java EE to understand the trivial: first, the schematic HTTP protocol

Source: Internet
Author: User

Writer:bysocket (mud and brick pulp carpenter)

Weibo: Bysocket

Watercress: Bysocket

Facebook:bysocket

Twitter:bysocket

Mason remembers and Zao Jianrong "blog Park" last chat, Dragon Brother asked a session of the question. What I understood at the time was foggy, start with the HTTP protocol understanding.

First, technical Cornerstone and Overview

Q: What is HTTP?
A: HTTP is a standard TCPfor client and server-side requests and responses . is actually built on top of TCP.

When we open the Baidu page, it is this:

Https://www.baidu.com

More than a s, in fact, s means TLS, SSL. There is no explanation here, so the technical cornerstone of http:

What about the HTTP protocol? The HTTP protocol (hypertext Transfer Protocol), the Hypertext Transfer Protocol, is the transport protocol used by the server to transfer to the client browser. On the Web, servers and clients use the HTTP protocol for communication sessions. There is the idea of OOP that the structure of its session is a simple request/response sequence, that is, the browser makes the request and the server responds.

Ii. in-depth understanding of technical cornerstones and workflow

Since HTTP is a transport-layer-based TCP protocol, the TCP protocol is a connection-oriented , end- to-end protocol. Therefore, before using the HTTP protocol to transmit, first establish a TCP connection, which is why the TCP link process in the talk of the "three-time handshake."

On the Web, the HTTP protocol uses the TCP protocol instead of the UDP protocol because a web page must transmit a lot of data and ensure its integrity. The TCP protocol provides transport control, which organizes the data sequentially and corrects a series of functions incorrectly.

An HTTP operation is called a transaction, and its working process can be divided into four steps:

1, the client and the server need to establish a connection. (such as a hyperlink, HTTP begins.) )

2. After the connection is established, the request is sent.

3. After the server receives the request, responds to its response information.

4. The information returned by the client receiving server is displayed on the user's display by the browser, and then the client disconnects from the server.

Establishing a connection is actually based on a TCP connection. The schematic core work process (i.e. eliminating the connection process) is as follows:

Third, the detailed work process of the HTTP message

HTTP messages consist of requests from the client to the server and responses from the server to the client.

One, the request message format is as follows:

Request Line

General Information Header

Request Header

Solid Head

(blank line)

Message body

, request the content of the message sent when I blog a post:

For a detailed description of the request message:

1. Request Line

Method field + URL + HTTP protocol version

2. General Information Head

Cache-control Header domain: Specifies the caching mechanism that requests and responses follow.

Keep-alive is its connection continues to be effective "in the following Baidu example, will be verified"

3. Request Header

Host header field, brain Repair bar

Referer header domain: Allows the client to specify the resource address of the request URL.

User-agent Header domain: request user information. "You can see the kernel information of some client browsers"

4. Message body

"p=278" in general, request parameters are required by the requesting principal.

second, the response message format is as follows:

Status line

General Information Header

Response header

Solid Head

(blank line)

Message body

, which is what this blog responds to:

A detailed description of the response message:

1, status line

HTTP protocol version + status code + text description of status codes

"Like here, 200 means the request succeeds."

2. General Information Head

Keep-alive is its connection continues to be effective "in the following Baidu example, will be verified"

Date Header field: Time description

3. Response Head

Server header: Software information for the originating server that processed the request.

4. Solid Head

Content-type Header: Is the media type of the receiver entity. (This also indicates what your message body is.) )

(blank line)

5. Message body

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

A simple request/response is complete.

Third, the HTTP Protocol knowledge Supplement

Request message Related:

Request line-Request method

Get
Request gets the resource identified by the Request-uri
Post appends new data to the resource identified by Request-uri
HEAD request Gets the response message header for the resource identified by Request-uri
PUT Request server stores a resource and uses Request-uri as its identity
Delete Request server deletes the resource identified by the Request-uri
TRACE requests the server to echo received request information, primarily for testing or diagnostics
CONNECT reserved for future use
Options request the performance of the query server, or query for resource-related choices and requirements

Response message Related:

Response Line-Status code

1XX: Indication information – Indicates that the request has been received and continues processing
2XX: Success – Indicates that the request has been successfully received, understood, accepted
3XX: Redirect – A further step must be made to complete the request
4XX: Client Error – Request syntax error or request not implemented
5XX: Server-side Error – Server failed to implement legitimate request

Common Status Codes

OK

The request succeeds (followed by the answer document for the Get and post requests.) )

304 Not Modified

The document was not modified as expected. The client has a buffered document and issues a conditional request (typically providing a if-modified-since header indicating that the customer only wants to update the document than the specified date). The server tells the customer that the original buffered document can continue to be used.

404 Not Found

The server was unable to find the requested page.

Internal Server Error

The request was not completed. The server encountered unpredictable conditions.

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

Refresh yourself:

The 304 above proves it.

1, 304 status code: Some pictures and JS files in the local client cache, again after the request, the cached file can be used.

2, above so the HTTP request, only a TCP connection, this is called the persistent connection .

Iv. Web application Framework or specification for HTTP protocol

Java EE people will know the servlet specification. Where the Web application container implements the objects in the HTTP protocol, the request and response objects. For example, there must be a description of the status code in the Javax.servlet.http.HttpServletResponse object,

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

V. Summary

Review the full text, the HTTP protocol is actually our conversation, language is one of the protocols. So master the HTTP protocol to understand the following points are good:

1. What to communicate via HTTP protocol

2. How to communicate via HTTP protocol

Writer:bysocket (mud and brick pulp carpenter)

Weibo: Bysocket

Watercress: Bysocket

Facebook:bysocket

Twitter:bysocket

Java EE to understand the trivial: first, the schematic HTTP protocol

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.