Javaweb Learning Note 1---HTTP protocol

Source: Internet
Author: User
Tags browser cache

First, what is the HTTP protocol:

1. Concept:

After the client connects to the Web server, if you want to obtain a Web resource in the Web server, you need to follow a certain communication format, the HTTP protocol is used to define the format of the client and Web server communication (to specify how the client and server interact).

HTTP is shorthand for the Hypertext Transfer Protocol (Hypertext Transfer Protocol), an application-layer protocol based on the TCP/IP protocol that defines the process of exchanging data between a Web browser and a Web server.

Note: The HTTP protocol is the cornerstone of learning Javaweb development, not in-depth understanding of the HTTP protocol, can not be said to master the Web development, but also unable to manage and maintain a number of complex web sites.

OSI Network layer Seven protocol:

Application layer (HTTP, FTP, SMTP, POP3, TELNET)-"presentation Layer-" Session layer-"Transport layer (TCP, UDP)-" Network layer (IP)-"Data Link layer-" physical layer

Note: The protocols for the transport and network layers are collectively referred to as the TCP/IP protocol.

2. HTTP request:

HTTP is transmitted in a request-response manner , a request corresponds to a response, and the request can only be issued by the client, and the server can only passively wait for the request to respond.

3. Win7 's own Telnet tool:

Using Telnet, you can simply demonstrate the process of requesting and responding. Win7 The Telnet feature is not turned on by default, to open in Control Panel:

The operation is as follows:

We first build a test.html page in the D:\apache-tomcat-8.0.14\webapps\MyTest directory, the effect is as follows: (Tomcat port has been changed to 80)

Then enter the following command in CMD:

telnet localhost 80

Then immediately press and hold the shortcut CTRL +], enter. The following command is entered immediately:

Get/mytest/test.html Http/1.1host:localhost

After two returns, you can see the content on the page:

This way is too troublesome, it is recommended to use the HttpWatch described below

4. HttpWatch Tools:

HttpWatch is provided specifically for IE and Mozilla Firefox, to view HTTP requests and the corresponding tools, which are helpful to our developers and enable us to learn the HTTP protocol better.

Once the installation is complete, you can see the plugin in Internet Explorer:

Clear the browser cache, re-enter the URL, the effect is as follows:

, the left side is the response from the browser, and on the right is the request returned by the server.

Again, the effect you see in Chrome is this:

5. The difference between HTTP1.0 and HTTP1.1:

    • In the HTTP1.0 protocol, after a client has established a connection with a Web server, only one Web resource can be obtained.
    • The HTTP1.1 protocol allows a client to obtain multiple Web resources on a connection after it has established a connection with the Web server.

Note: Generally speaking, the difference is only one: when the client and the Web server after the connection (the bottom is the flow of operations), if the use of the HTTP1.0 protocol, the flow will immediately break, HTTP1.1 protocol, the stream will be saved for a period of time, the next time you reconnect, continue to use this stream.

Issue: In a Web page, three images were referenced using the IMG tag, and when the client accesses the Web page in the server, the client accesses the server a few times, sending several HTTP requests to the server.

Answer: 3 times.

Second, the difference of Get/post request:

Note: The GET Request method differs from the POST request in that the request parameters are in different ways during delivery

    • GET request Mode : Explicit request, request parameters will be displayed on the URL, relatively fast, security is low, the size of the request data is generally not more than 1kb.
    • POST request Mode : Implicit request, request parameters will be transferred in the entity content of the HTTP request, relatively slow, high security, the size of the request data is not limited

Third, common request header and corresponding head:

Or look at the page above:

The first behavior requests the line, the remainder is the request header, the entity content.

Request Line: get/mytest/test.html http/1.1 request method, name of the requested resource part, protocol version followed

1. Common Request headers:

    • host:www.baidu.com      host address (virtual host name) accessed by this request
    • Cache-control:no-cache         how to set up Web cache usage
    • pragma:no-cache
    • Accept : Text/html,xxxxxx ..... data types that the client can receive (if the content is: */*, which means that all types are received)
    • user-agent :mozilla/5.0xxxxx  mainly represents the client type
    • accept-encoding : The Gzip,deflate,sdch browser can receive the data compression encoding (indicates what format the browser can receive compressed data)
    • accept-language : The type of language that the zh-cn,zh;q=0.8 browser expects to accept
    • accept-charset:iso-8859-1       client received character set encoding
    • If-modified-since:tue, 18:23:51 gmt   and cache mechanism related headers
    • referer:http://www.smyh.me/index.jsp   the page from which the current page came from (possibly from a previous page through a hyperlink contact)
    • Cookie
    • connection:close/keep-alive   The connection is closed after the request is complete, or continue to remain connected
    • Date:tue, 18:23:51 GMT current request time

Note: The above refers to the request header of the GET request.

Then look at the content on the right side of the first page:

The first behavior status line, followed by the response header, the entity content.

Status line: http/1.1 OK protocol version, status code, reason narration <CRLF>

"Status Code"

Status code: Used to represent the result of the server's processing of this request, which is a three-bit decimal number. The response status code is divided into 5 classes, as follows:

Common status codes are as follows:

    • 200 successfully received the request
    • 302 the ability to implement redirection
    • 304/307 using cached resources built into the browser
    • 404 Client Request Error
    • 500 Server Segment Error occurred

2. Common Response Head:

Common meaning of the response header key value pairs:

  • location:http://www.smyh.me/index.jsp Redirection (302+location implementation redirect)
  • Server type
  • Content-encoding the data compression format that the server is currently returning to the client
  • Content-length the size of the amount of data returned to the client
  • CONTENT-LANGUAGE:ZH-CN language Types
  • content-type: text/html; CharSet=gb2312 The type of data returned, the character set encoding returned (by setting the charset, allowing the browser to decode in the specified manner)
  • Last-modified the last time the resource was modified (in conjunction with the if-modified-since+304/307 in the request header to implement the caching mechanism)
  • refresh:1;url=http://www.it315.org How many seconds later, so that the current page to access which address (such as Web landing success, 3 seconds after jumping back to the original interface, it is used this head)
  • content-disposition: attachment;filename=aaa.zip and download related, notify the browser to download the server as an attachment to send past data
  • transfer-encoding:chunked Data transfer Mode
  • SET-COOKIE:SS=Q0=5LB_NQ; Path=/search and cookie-related headers
  • etag:w/"83794-1208174400000" and cookie-related headers
  • Expires: 1 Notifies the browser whether the current resource is cached: If the value of this header is a value in milliseconds, notifies the browser to cache the resource to a specified point in time, or if the value is 0 or-1, notifies the browser to disallow caching
  • Cache-control:no-cache notifies the browser whether to cache resources
  • Pragma:no-cache--Notifies the browser whether to cache resources

Note: The top three headers are a feature because of historical reasons. Different browsers have different support for these three headers, in general, these three headers should be used at the same time to ensure that different browsers can implement the ability to control the cache

    • Connection:close/keep-alive whether to keep the connection
    • Date:tue, 18:23:51 GMT Current response time

Javaweb Learning Note 1---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.