Web request in layman's

Source: Internet
Author: User
Tags browser cache

Web request Process

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/89/81/wKioL1gV7qXBwVPRAAB9ZZ9KIH8858.png "title=" Sogou _ 2016-10-30_19-29-28.png "alt=" Wkiol1gv7qxbwvpraab9zz9kih8858.png "/>

1. Advantages of b/S architecture


First, the client is unified

Users face the client---browser is unified, the interaction is friendly, and the learning cost is low, just learn a Web application operation, then the application of other Web pages is easy to operate and learn, that is, the user's ability is inheritable. If based on the C/S architecture, then it is not unified.


Second, the service-side unified

The protocol of the B/S interactive bridge is unified for HTTP. Unlike the C/S architecture, the protocol is based on application business and will not be unified. Since it is all based on HTTP, there will be a lot of out-of-the-box HTTP server and framework, we can directly use, only need to focus on business implementation, easy to develop.



2. Domain-to-IP conversion


To know the domain-to-IP conversion, is cached, then since the cache, you need to know that there is space and time constraints. This is mainly the TTL limit. Local domain name resolution is mainly reflected in the Hosts file, if the local can not be determined, then sent to the DNS server for resolution (typically the network configuration is specified in the nameserver address), if the DNS server in the region can not be determined, it will be processed through root DNS.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/89/81/wKioL1gV9__CP14nAABYqUsI26Q811.png "title=" Sogou _ 2016-10-30_21-39-15.png "alt=" Wkiol1gv9__cp14naabyqusi26q811.png "/>



Key points of the 3.HTTP protocol


No status

The so-called stateless, refers to the HTTP request is not related to the last HTTP request, on the service side is unable to record 2 requests for transactional. But in real life, we need a sort of order, such as adding a shopping cart first, then ordering, then paying. To record this state, there is a cookie and a session.



Short connection

HTTP1.0 default is a short connection, HTTP1.1 is a long connection by default.

The so-called short connection, refers to an HTTP request, the client is disconnected from the server. A long connection is a time limit when you disconnect after multiple HTTP requests, you need to mark Connection:keep-alive in the HTTP request header, and of course you do not keep the connection permanently. On the surface, long connections omit frequent connections, and the steps to close connections seem to be better than short connections. However, in many scenarios, short connections are advantageous. For example, in a huge number of user requests, for each user to maintain a connection, this resource is not enough, in this context, many times is to use a short connection, in order to meet the request of a huge amount of users.


HTTP Header

The most critical data in the HTTP protocol is the HTTP header, why? Because the HTTP header controls the rendering behavior of the browser client and the execution logic of server-side servers.


Coding Related:

Request Header (accept-charset/accept-encoding/accept-language)

Response Header (content-type/content-encoding/content-language)


Connection Related:

Request Header (Connection)

Response Header (keep-alive)


Client information Related:

Request Header (host/user-agent)


Cache correlation:


For HTTP caching, there are several levels of cache that need to be clarified: Browser cache, Server cache

To see the latest data, first make a request directly to the server without using the browser cache, and secondly, after the server receives the request, it does not use the server-side cache data. [Some servers may use HTTP cache proxy]


Why do we use CTRL+F5 to send a request to the server without using the browser cache instead of the latest data? In essence, it is in the HTTP header to do some hands and feet.


Pragma:no-cache

Cache-control:no-cache


If we do not indicate not caching in the HTTP header, when does the browser not use the browser cache?


Expires : page expiration, time exceeded, page failure, browser will make a request to the server.

last-modified : The last modification time, if the client and server side of the 2 values of the same, then obviously there is no need for clients to request the latest server resources.



HTTP Status Code


2XX , success, such as

3XX , such as 302 redirect temporary jump, 304 client resource is up-to-date without server return resource (last-modified)

4XX , client error, such as 404 Resource not present, 403 resource Forbidden

5XX , service-side errors, such as



4. The nature of the HTTP protocol from the Java point of view


For example, the user entered a URL in the browser after the return, is actually established a socket connection, IP is the result of the domain name conversion, the port is the default 80, and then the browser based on the URL to assemble an HTTP The GET request is sent through Outputstream.write, and then the server reads the data through Inputstream.read and writes back the HTTP GET response to the client via the output stream.

Summing up, one sentence, an HTTP request, is the process of a socket communication.


5.curl command


We can either simply make HTTP requests through the browser, or we can use an open source toolkit such as httpclient to make HTTP requests, as well as the command that comes with Linux: Curl


For example, there is a scenario like this:


We need to communicate with the message queue MQ, the communication protocol uses HTTP, but with the L5 load balancing mechanism, we can not directly access MQ and need to be forwarded through a proxy, then we can quickly test the link via Curl:


Curl-h "Host:zzz" http://xxx:yy/


Xxx:yy is the IP and port that L5 sent us, and zzz is the domain address that really we need to access MQ.


Description

-H HTTP protocol Specifies header headers

-I view HTTP header header information


6.CDN Job Description


A CDN, a content distribution network, distributes the content of a site to the nearest user in the Internet, allowing users to get what they need nearby, increasing the speed with which users visit the site. After the average user gets the dynamic data, the static resources are taken from the CDN, which accelerates the download speed of the webpage data.


7. Load Balancing


DNS-Level load balancing

DNS can be used to resolve the domain name dynamically get different IP, so as to achieve load allocation, but the disadvantage is that the user is directly linked to the backend service IP, once the background Web server hangs, then the client and DNS too late to update, the consequences are very serious.


Hardware-Level load balancing

With very expensive hardware to achieve, generally can not afford the price, and there are restrictions.


Software-Level load balancing

is actually implemented through multi-tier proxy forwarding. This approach is used in practice.







This article is from the "Boundless Mind Infinite" blog, please be sure to keep this source http://zhangfengzhe.blog.51cto.com/8855103/1870067

Web request in layman's

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.