The topic of this blog post is Web Services ha. WEB services are also the most used services on the Internet, often referred to as the WWW (World Wide Web) service.
"The main content of this blog post"
First, the HTTP protocol base:
1. What is http:
HTTP: Hypertext Transfer Protocol, Hypertext Transfer Protocol, defines how the browser (that is, the World Wide Web client process) requests the World Wide Web server for Web documents, and how the server transmits the document to the browser. From a hierarchical point of view, HTTP is an application-layer-oriented protocol (transaction-oriented), which is an important basis for reliably exchanging files (including text, sound, images, and other multimedia files) on the World Wide Web.
HTML: Hypertext Mark Language, Hypertext Markup Language, contains hyperlinked documents that are presented to the user through browser parsing.
2. How HTTP Works:
The work of the HTTP protocol works roughly as shown:
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px ;p adding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "Title=" 0354A36E-C6D0-486A-BF15-6DC7C93DAE1E "border=" 0 "alt=" 0354a36e-c6d0-486a-bf15-6dc7c93dae1e "src="/http S3.51cto.com/wyfs02/m02/6d/9b/wkiom1vneuvicgqlaagpi9gody4652.jpg "height=" 444 "/>
"HTTP Transaction"
The composition of a transaction consists of the completion of the entire process of request+response, that is, a request is combined with a corresponding response message to be an HTTP transaction .
the completion process of an HTTP transaction (as shown):
Establish a connection----> The client establishes a connection with the Web server through the DNS resolved IP address;
Receive requests----The >web server receives requests from clients;
Processing the request---->web the server to parse the request message and make the corresponding action;
Access to resources----The >web server accesses the related resources requested in the request message in its own database;
Build the response----The >web server uses the correct header to generate HTTP response messages;
Send a response----The >web server sends a generated response message to the client;
Logging —---The >web server logs the completed HTTP transaction into the log file;
"Web Resources"
Each file requested by the client (including every picture) is a Web resource
Here's a look at a specific HTTP transaction through the developer tools of the browser:
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px ;p adding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "Title=" cd9837fc-5709-446c-b409-0f7a1b72e45f "border=" 0 "alt=" cd9837fc-5709-446c-b409-0f7a1b72e45f "src="/http S3.51cto.com/wyfs02/m00/6d/96/wkiol1vneuxhugr8aajqunizeao822.jpg "height=" 218 "/>
As you can see, the amount of time the server spends processing requests to build responses is a major part; each file requested by the client (every HTML document, every picture) is a web resource, and each Web resource gets an HTTP request
3, the characteristics of HTTP
c/S Architecture :
Client: Clients interact with the server using a browser
Server: The mainstream Web server has httpd (Apache), Nginx,lighttp,thttpd,iis
Message type:
HTTP is an application-layer protocol (based on the request/response model)
Request message: Requests
Response message: Response
no connection: restricts the processing of one request per connection. After the server finishes processing the customer's request and receives a response from the client, the connection is disconnected.
stateless: There is no memory capability for transactions (that is, when the client's request arrives and the server responds, the connection is closed). This means that if the subsequent processing requires information from the previous request, it must be re-transmitted, each request is independent from the previous request, the order of the requested resource is determined by the client browser, and the server does not know whether the resource requested by the client is a page or multiple pages.
Tips: Take an example to understand the stateless nature of the HTTP protocol:
For example, when a user visits an e-commerce site and puts a product into a shopping cart, a refreshed page will reveal that the shopping cart is empty (how do I fix this problem?). Through the session technology--cookie/session mechanism), the principle is roughly as follows:
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px ;p adding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "Title=" dc8d69f2-8e83-4035-9db8-b66b4e4c9907 "border=" 0 "alt=" dc8d69f2-8e83-4035-9db8-b66b4e4c9907 "src="/http S3.51cto.com/wyfs02/m01/6d/96/wkiol1vneuqwtj4gaajeyru-14w932.jpg "height=" 501 "/>
4, the version of the HTTP protocol:
http0.9: the first mature version
http1.0:
(1) The introduction of MIME technology, enabling the ability to support multimedia functions (the browser can only display plain text, it operates non-text files in two ways: 1, through the browser's internal plug-in 2, call the external corresponding program)
MIME(mutipurpose Internet Mail Extension: Multi-functional Internet Mail Extension): Provides support for non-text attachments to the SMTP protocol (only plain text is supported by SMTP by default)
"MIME of various file formats"
Major (Major Version)/minor (minor version number)
Pictures of image/jpg:jpg format
Pictures of image/gif:gif format
Text/html: Plain Text file
Video/quicktime: Video files
application/x-httpd-php: Applications (Programs handled by PHP)
(2) Keep-alive (maintain connection): that is, TCP/IP three-time handshake will not immediately disconnect, but wait to continue to obtain resources, no resources to get or time out before disconnecting
(3) Short connection: Cut off immediately after connection
(4) Support caching (faster opening of web pages)
http1.1 (Mainstream):
Support for more Request methods
Support for finer cache control (conditional requests)
Support for persistent connections (persistent connection)
Support for Virtual hosts
5. HTTP Identity Resource method:
think of a question : How does a browser get a resource, how to differentiate between different resources at the same site and the same type of resources at different sites? Use URIs to identify different types of Web resources?
Uri:uniform Resource Identifier (Unified resource Identifier)
URL: Uniform Resource Locator (URL is a subset of URIs, URLs are generally used on the Internet)
Format:scheme://[username:[email protected]]host:port/path/to/source
Example: http://www.magedu.com/downloads/nginx-1.5.tar.gz
Web file: There is a storage location in the file system, if it is/www/html
URN: Uniform Resource Name
6. Brief introduction of dynamic website technology and CGI:
The advent of CGI (common Gateway Interface) technology introduces dynamic site technology:
Dynamic site : The user requests a program, the execution results of the program back to the user, according to the location of the program run is divided into client dynamic and server-side dynamic:
CGI principle : The client opens a page to see how the server-side time is implemented?
Without CGI, the server returns a script that displays the time command directly to the client (for example, the returned content is #!/bin/bash date)
Through some protocol (CGI), the Web server communicates with the program execution Environment (as shown):
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px ;p adding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "Title=" eb7e4777-021b-416c-8928-41a41af88376 "border=" 0 "alt=" eb7e4777-021b-416c-8928-41a41af88376 "src="/http S3.51cto.com/wyfs02/m01/6d/96/wkiol1vneu3xqlolaae_rb1iz-y856.jpg "height=" 343 "/>
7, HTTP caching mechanism: (Multi-level chain cache)
Private cache: A private resource such as a browser
Public cache: Static files such as slices, text, etc.
Proxy, Bypass cache server (DNS-like recursion)
Second, the HTTP request message and Response message detailed:
"format of HTTP message":
An HTTP message consists of 3 parts, namely:
Start lines (start line)
Header (header) : There are multiple headers, most commonly used are general header, request/response header, entity header
Body (body)
"header of HTTP message"
Universal header: Both requests and responses can be used
Connection: Allow clients and servers to specify options related to request/response connections
Date: Provides a day and time flag indicating when the message was created
Mime-version: Gives the MIME version used by the sending side
Trailer: If the message uses a chunked transmission encoding (chunked transfer encoding), you can use this header to list the header set in the Message Trailer section.
Transfer-encoding: Inform the receiving side in order to ensure the reliable transmission of the message, the message adopted what encoding method.
Update: Gives the new version or protocol that the sending side might want to "upgrade"
Via: Shows the intermediary node (proxy, Gateway) of the message passing through
Request Header:
Host: The requested hosts
Referer: Provides the URL of the document containing the current request URI
Accept: The MIME type accepted
Accept-charset: The character set accepted by the browser
Accept-encoding: The type of encoding supported by the browser
Accept-lanague: Tell the server which languages to send
Conditional request Header: For controlling caching
If-modified-since: Restricts the request unless the resource has been modified after a specified date
If-none-match: Works with the etag and works by adding etag information to the HTTP response. When the user requests the resource again, the If-none-match information (the value of the ETag) is added to the HTTP request. If the server verifies that the etag of the resource has not changed (the resource is not updated), it returns a 304 status that tells the client to use the local cache file. Otherwise, the 200 state and the new resource and ETag are returned. Using such a mechanism will improve the performance of your website
Security Request Header:
Authorization: Authentication information provided to the server by the client;
Cookie: The client uses it to send a tiny piece of information to the server-it's not a real security header, but it's an implicit security feature.
Cookie2: The cookie version used to describe the request-side support
Response header:
Age: (starting from initial creation) response duration
Public: Whether it can be cached on the common cache
Server: Software name and version
Vary: The list of other headers viewed by the server may cause the response to change; that is, this is a first list, the server will pick out the most appropriate version of the resources according to the contents of these headers to send to the client (which will affect the caching mechanism);
Set-cookie: Setting cookies
Set-cookie2: Similar to Set-cookie
Entity Header:
Allow: the allowed Request method
Location: The actual position of the resource
Content-language: The most appropriate natural language to understand the subject
Content-location: Where the resources are actually located
Content-type: MIME type of resource
ETAG: Entity Tag
Expires: The entity is not valid, to obtain the date and time of this entity from the original source side again
Last-mofified: The date and time this entity was last modified
1. HTTP Request message:
" format of Request message":
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px ;p adding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "Title=" 57f2666f-548e-4fff-a0b9-dd55cf6b7191 "border=" 0 "alt=" 57f2666f-548e-4fff-a0b9-dd55cf6b7191 "src="/http S3.51cto.com/wyfs02/m02/6d/96/wkiol1vneu2cthieaaaylva9ybg676.jpg "height="/>
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px ;p adding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "Title=" 1e67046a-f52d-408f-a10e-60a643b78e3e "border=" 0 "alt=" 1e67046a-f52d-408f-a10e-60a643b78e3e "src="/http S3.51cto.com/wyfs02/m00/6d/96/wkiol1vnevtqmwxeaanphshxlio528.jpg "height=" 447 "/>
"Detailed HTTP request message":
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px ;p adding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "Title=" 8f0f1100-cbce-453e-90b9-94bb6570b3dd "border=" 0 "alt=" 8f0f1100-cbce-453e-90b9-94bb6570b3dd "src="/http S3.51cto.com/wyfs02/m01/6d/96/wkiol1vnevnzn3i9aanj6q0tjwu389.jpg "height=" 209 "/>
"Request method for HTTP protocol":
GET: Complete request for a resource
HEAD: Request response header only (no subject required)
POST: Submit Forms and Attachments
PUT: The method of uploading resources, dependent on the mechanism of WebDAV (unsafe);
Delete: The method of deleting the resource, dependent on the WebDAV mechanism (unsafe);
Options: Methods to return the methods supported by the requested resource
Trace: Trace a proxy server that passes through the middle of a resource request
Description: the HTTP request method mainly has two--get and post, the difference between the two is as follows:
(1) Security: Get request data will be displayed in the Address bar;
The data of the post request is placed in the message body of the HTTP protocol;
(2) from the size of the data can be submitted to see:
The HTTP protocol itself does not limit the size of the data, but the browser has restrictions on the data for Get and POST requests:
Get: (2k+35=2083) bytes
Post: No Limit
(3) Get request can be added to favorite folder better
2. HTTP Response message:
"Format of Response message":
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px ;p adding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "Title=" 30997d0b-841e-44c4-a981-a04e3a5c974d "border=" 0 "alt=" 30997d0b-841e-44c4-a981-a04e3a5c974d "src="/http S3.51cto.com/wyfs02/m02/6d/96/wkiol1vnevqxivmxaaawcdxktho332.jpg "height=" "/>"
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px ;p adding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "Title=" 755423cd-e7ec-49e6-9a13-eb93b9a35e98 "border=" 0 "alt=" 755423cd-e7ec-49e6-9a13-eb93b9a35e98 "src="/http S3.51cto.com/wyfs02/m02/6d/96/wkiol1vnev3y_hxnaaf2qmc9kdy060.jpg "height=" 361 "/>
"HTTP Response message Details":
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;margin:0px;padding-left:0px ;p adding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "Title=" 4d9256f4-1064-4b62-ac1f-416cd115c15d "border=" 0 "alt=" 4d9256f4-1064-4b62-ac1f-416cd115c15d "src="/http S3.51cto.com/wyfs02/m02/6d/9b/wkiom1vnewzapd4eaahnlirudy4323.jpg "height=" 191 "/>
"HTTP response code":
650) this.width=650; "Style=" background-image:none;border-bottom:0px;border-left:0px;padding-left:0px; padding-right:0px;border-top:0px;border-right:0px;padding-top:0px; "Title=" 0e2497fd-2347-4faf-834e-c06d99b40118 "border=" 0 "alt=" 0e2497fd-2347-4faf-834e-c06d99b40118 "src=" http://s3.51cto.com/wyfs02/M00/6D/96/ Wkiol1vnewkcdqpgaagxqwc454e320.jpg "height=" 229 "/>
1xx: Informational Status Code
100, 101
2xx: Success Status Code
200:ok
3xx: Redirect Status code
301: Permanent redirect, the value of location response header is still the current URL, so it is implicitly redirected;
302: Temporary Redirect, explicit redirect, location response header value for new URL
304:not Modified (not modified, useful in conditional requests)
4xx: Client Error status Code
404:not Found
5xx: Server-side error status code
500:internal Server Error
502:bad Gateway (any agent cannot find its upstream agent)
504:gateway Timeout
Iii. common Web Server software and browsers:
Web Server Software:
HTTPD: (Apache), a patchy server,
Asf:apache Software Foundation
Tomcat
Cassandra
Hadoop
Cloudstack
Lucene
Nginx
Lighttpd
IIS;
Web browser:
Ie
Chrome
Firefox
Opera
Safari
ELinks
Curl
The content of this blog is so Doha, next time we will specifically talk about the Apache (httpd) server basic configuration.
This article is from the "Tech log" blog, so be sure to keep this source http://sweetpotato.blog.51cto.com/533893/1656137
Linux op Koriyuki web base (http base)