HTTP protocol Tutorials

Source: Internet
Author: User

Article content:

1.HTTP Protocol Overview

2.URL Knowledge Overview

3.HTTP Message Structure Detailed

1.HTTP Protocol Overview

Defined:

    • The Hypertext Transfer Protocol (Http-hypertext Transfer Protocol) is a communication protocol between distributed Hypermedia system applications and is the basis for the World Wide Web (WWW) exchange of information. It allows Hypertext Markup Language (HTML) documents to be routed from the Web server to the client's browser;
    • HTTP works on TCP protocol in TCP/IP protocol system;
    • Now the WWW is used by http/1.1, which was developed by RFCs (requests for comments) in June 1990.

Characteristics:

Simple and fast: When a customer requests a service from the server, it simply transmits the request method and path. The request method commonly has, POST. Each method specifies a different type of contact between the customer and the server. Because the HTTP protocol is simple, the HTTP server's program size is small, so the communication speed is fast.
Flexible: HTTP allows the transfer of any type of data object. The type being transmitted is marked by Content-type.
Stateless: The HTTP protocol is a stateless protocol. Stateless means that the protocol has no memory capacity for transactional processing. A lack of state means that if the previous information is required for subsequent processing, it must be re-transmitted.

HTTP Transport Steps/procedures:

    • Establish a TCP connection
    • Web browser sends request command to Web server
    • Web browser sends request header information
    • Web server Answer
    • Web server sends answer header information
    • Web server sends data to browser
    • Web server shuts down TCP connection/or remains connected
2.URL Overview

URL definition:
The Uniform Resource Locator (URL, abbreviation for English uniform/universal Resource Locator) is an identifying method that is used to fully describe the addresses of web pages and other resources on the Internet.

URL format:

The basic format is as follows
schema://host[:p ort#]/path/.../[?query-string][#anchor]
Schema protocol (for example: HTTP, HTTPS, FTP)
The IP address or domain name of the host server
port# the port of the server (omit if you are going to the protocol default port)
Path to access resource
query-string parameters, data sent to the HTTP server
anchor-anchor (jumps to the specified anchor position of the Web page)

An example of a URL :
Http://www.website.com/test/test.aspx?name=sv&x=true#stuff

A request process for a URL:

    • When you enter the URL http://www.website.com in the browser, the browser sends a request to get the http://www. website.com HTML. The server sends the response back to the browser.
    • The browser parses the HTML in response and discovers that it references a lot of other files than slices, CSS files, and JS files.
    • The browser will automatically send the request again to get a picture, CSS file, or JS file.
    • When all the files are downloaded successfully, the page is displayed.
3.HTTP Message Structure

HTTP messages are divided into HTTP request messages (HTTP requests) and HTT response (HTTP Response) messages.

The HTTP request message, which consists of three parts:

Part 1th called request line

The 2nd part is called the request header.

The 3rd part is the body (there is a blank line between the header and the body).

As shown in the following:

HTTP request message

The HTTP request message is described in detail below:

    • Method: Represents the request methods, such as post, get and put, etc.;
    • Path-to-resoure : Represents the requested resource.
    • Http/version-number : Represents the version number of the Http protocol, such as http/1.1
    • request message Common Methods : HTTP defines different methods of interacting with the server, the most basic method has 4 kinds, respectively, is get,post,put,delete, corresponding to the resources of the search, change, increase and delete 4 operations. General get is used to get/query resource information, post is generally used to update resource information; This should be the essential difference between get and post;

Get/post Example of request message:

Get instance:

get/test/?id=11101&name=professional http/1.1  Host:www.test.com User-agent:mozilla /5.0 (Windows; U;) firefox/1.0. 1 Connection:keep-alive

POST instance:

post/http/1.1  Host:www.test.com  User-agent:mozilla/5.0 (Windows; U) firefox/1.0. 1 content-type:application/x-www-form-urlencoded content  connection:keep- Alive (...) Empty line here ... ) name=professional&id=11101

Learn more about HTTP request messages:

    • Get commits, the requested data is appended to the URL (that is, it is placed in the HTTP protocol header) to "?" Split URL
      Data, multiple parameters are connected with "&", for example:
      Login.action?name=tom&password=securiy
    • Post submission: Place the submitted data in the body of the HTTP package. In the example above, name=professional&id=11101 is the actual transfer data;
    • Data length: The HTTP protocol does not restrict the length of the transmitted data and URLs, but the specific browser and server limit the length of the URL, so for a get commit, the transmission of data will be limited by the URL length, because the post operation is not through the URL value, theoretically the length of the data is not limited;
    • Security: Post security is higher than get security, through get submit data, user name and password will appear in plaintext on the URL, easy to be seen by others, URL information may also be recorded in the history record;

HTTP Response message (HTTP Response), consisting of three parts:

1th part called response line

The 2nd part is called response header.

The 3rd part is the body (there is a blank line between the header and the body).

HTTP Response Message

The HTTP response message is described in detail below:

    • The version number of the Http/version-number:http protocol;
    • Status-code: Status Code
      1XX hint Message-Indicates that the request was successfully received and continues processing
      2XX Success-Indicates that the request has been successfully received, understood, accepted
      3XX Redirect-further processing is required to complete the request
      4XX Client Error-Request syntax error or request not implemented
      5XX server-side error-the server failed to implement a legitimate request
    • Message: Status message
    • The most common status codes for request lines:
      (OK): The resource was found and everything is OK.
      304 (not MODIFIED): The resource has not been modified since the last request. This is commonly used for browser caching mechanisms.
      401 (Unauthorized): The client does not have permission to access the resource. This usually causes the browser to require the user to enter a user name and password to log on to the server.
      403 (FORBIDDEN): Client failed to get authorization. This is usually followed by an incorrect user name or password that was entered after 401.
      404 (Not FOUND): The requested resource does not exist at the specified location.

To do Next:

HTTP header (HTTP request header)

HTTP response Header (HTTP Request header)

HTTP encoding and decoding (HTTP Encode/decode)

HTTP protocol Tutorials

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.