Detailed analysis and http

1. What http yes?
http is a hypertext transfer protocol formerly known as the Hypertext Transfer Protocol - HTTP / 1.1
can Baidu see RFC document number RFC-2616 for http connections here https://tools.ietf.org/html/rfc2616

2, http protocol What is the role?
We can understand http protocol is a way between hypermedia information transmission protocol used in the World Wide Web media information exchange.

3, http agreement look like?
For example:
http://i.cnblogs.com/EditPosts.aspx?opt=1
example:
http://www.baidu.com

This is a network address, in response to the Internet is mapped to the center of the media resource corresponding to a resource storage location,

4, the format http protocol is what?
http protocol format referred to http URL

protocol://[host.]domain[:port][/context][/resource][?query string | path variable]

或者
protocol://ip address[:port][/context][/resource][?query string | path variable]

Summarized as follows: protocol name + domain name | IP address and port number + resource request parameters relative paths +

5. What is the URL is the HTTP?
HTTP uses uniform resource identifier (Uniform Resource Identifiers, URI) to transmit data and establish a connection. URL is a special type of URI, it contains enough information for finding a resource

URL, stands for UniformResourceLocator, Chinese called a Uniform Resource Locator, is the address used to identify a resource on the Internet at. At the following URL as an example, each part of the composition of the next ordinary URL:

http://www.aspxfans.com:8080/news/index.asp?boardID=5&ID=24618&page=1#name
can be seen from the above URL, a full URL includes the following parts:
5.1 part of the protocol: The protocol part of the URL is "http:", which represents the web page using the HTTP protocol. More may be used in the Internet protocols, such as HTTP, FTP and the like used in this example is the HTTP protocol. In the "HTTP" behind "//" is a delimiter

5.2 domain name parts: the part of the URL of the domain name "www.aspxfans.com". A URL, or you can use the IP address as the domain name

5.3 port sections: following the domain name is to use between the ports, the domain name and port ":" as the delimiter. Port is not a mandatory part of the URL, if you omit part of the port, the default port

5.4 virtual directory section: from the first domain name after the "/" beginning to the last "/" so far, is the virtual directory section. Virtual directory is not a necessary part of the URL. In this example the virtual directory is "/ news /"

5.5 file name parts: from the last after the domain name "/" beginning to date, is the filename part, if not, it is from the last after the domain name "/" beginning to "#" so far "?" "?" , is part of the file, if there is no "?" and "#", then the domain name from the last "/" start to finish, it is part of the file name. In this case the file name is "index.asp". Part of the file name is not a necessary part of the URL, if you omit this part, the default file name

5.6 anchor part: From the "#" beginning to end, are part of the anchor. Anchor of this embodiment is "name". Anchor part of the URL is not a necessary part

5.7 Parameters section: from the beginning to the part of the argument between the part until the "#", also known as part of the search query part of the "?". Parameters of this embodiment is "boardID = 5 & ID = 24618 & page = 1". Parameter to allow a plurality of parameters, with the parameters between the parameter and the "&" as the delimiter.

(Original: http: //blog.csdn.net/ergouge/article/details/8185219)

6, the difference between URI and URL of
URI, is the uniform resource identifier, uniform resource identifier, used to uniquely identify a resource.
Each resource available on the Web such as HTML documents, images, video clips, programs are to a URI to locate the
URI is generally composed of three:
① access to the resource naming scheme
② storage resource host name
③ name of the resource itself , represented by the path, with emphasis on resources.

URL is a uniform resource locator, Uniform Resource Locator, which is a specific URI, namely URL can be used to identify a resource, but also indicates how locate this resource.
URL is a string used to describe the information resources on the Internet, mainly used in various WWW client and server programs, especially the famous Mosaic.
URL can adopt a uniform format to describe a variety of information resources, including file, the server's address and directories. URL is generally composed of three:
① agreement (otherwise known as service mode)
② there IP address of the host resources (sometimes including the port number)
specifically address ③ host resources. Such as directory and file name, etc.

URN, uniform resource name, uniform resource name, the resource is identified by name, such as mailto: [email protected].
URI is an abstract, high-level definition of the concept of uniform resource identifier, and the URL and URN are specific resources identified. URL and URN is a kind of URI. Broadly speaking, each URL is a URI, but not every URI is a URL. This is because the URI also includes a subclass, or Uniform Resource Name (URN), which named resource but does not specify how to locate resources. The above mailto, news, and examples are a URN isbn URI.

In Java's URI in a URI instance it can represent absolute or relative, as long as it meets the URI syntax rules. The URL class is not only in semantics, also contains information to locate the resources, so it can not be a relative.
In the Java class library, URI class does not contain any method to access the resource, its only function is to resolve.
In contrast, URL class can open a flow of resources to reach.

7, part of the http protocol of what?
Inside a complete http protocol has the following components
such as:
GET /562f25980001b1b106000338.jpg HTTP / 1.1
Host img.mukewang.com
the User-Agent Mozilla / 5.0 (Windows NT 10.0; WOW64) AppleWebKit / 537.36 (KHTML, like Gecko) Chrome Safari /51.0.2704.106 / 537.36
the Accept Image / WebP, Image / , /*;q=0.8
the Referer http://www.imooc.com/
the Accept-Encoding the gzip, the deflate, SDCH
the Accept-Language-the CN ZH, ZH; Q = 0.8

The above is a http get requests

7.1HTTP Request message requesting the
client sends a request to the server HTTP request message comprises the following format:

Request line (request line), the request header (header), a blank line portion and four request data.

Http request message structure .png
request line method begins with a symbol, separated by spaces, URI, and the protocol version followed by a request.
Examples Get request, Charles captured using Request:
the GET /562f25980001b1b106000338.jpg the HTTP / 1.1
the Host img.mukewang.com
the User - Agent-the Mozilla / 5.0 (the Windows NT 10.0; the WOW64) AppleWebKit / 537.36 (KHTML, like the Gecko) the Chrome / 51.0 Safari .2704.106 / 537.36
the Accept Image / WebP, Image / , /*;q=0.8
the Referer http://www.imooc.com/
the Accept-Encoding the gzip, the deflate, SDCH
the Accept-Language-the CN ZH, ZH; Q = 0.8
first part: the request line, for explaining the type of request to access the resource, and HTTP version being used.
the GET request type GET, [/ 562f25980001b1b106000338.jpg] to access the resource, the last part of the line of instructions is HTTP1.1 version.

Part II: request header, immediately after the request line portion (i.e., first row), for explaining the additional information server to be used
from the second row is a request header, the HOST will be the destination of the request .User -Agent, server-side and client-side script can access it, it is an important basis for the type of browser detection logic. this information is defined by your browser, and automatically sent with each request, etc.

Part III: blank line, a blank line back to the request header is required
even if a fourth request data section is empty, empty line must be.

Part IV: The request also called data subject, you can add any other data.
Examples of this request data is empty.

POST请求例子,使用Charles抓取的request:
POST / HTTP1.1
Host:www.wrox.com
User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Content-Type:application/x-www-form-urlencoded
Content-Length:40
Connection: Keep-Alive

name = Professional% 20Ajax & publisher = Wiley
first portion: the request line, the first line is clear post request, and http1.1 version.
Part II: request header, the second to sixth rows.
Part III: blank lines, blank lines seventh row.
Part IV: request data, the eighth line.

The Response message in response 7.2.HTTP
Generally, the server receives and processes requests sent, the client returns a response message of HTTP.

HTTP response also consists of four parts, namely: a status line, message header, and response body blank line.

http response message formats .jpg
Examples

HTTP/1.1 200 OK
Date: Fri, 22 May 2009 06:07:21 GMT
Content-Type: text/html; charset=UTF-8

Part I: status line, by the HTTP protocol version, status code, a status message of three parts.
A first status line behavior, (HTTP / 1.1) shows that HTTP version 1.1 version, status code 200, status message (ok)

Part II: message header, used to illustrate some of the additional information of the client to use
the second and third behaviors message header,
a Date: The date and time of generation of a response; Content-Type: Specifies the MIME type of HTML (text / html), encoding type is UTF-8

Part III: blank line, blank line after the message header is required
Part IV: response body, the server returns the text information to the client.
Html part blank line after the response body.

8, HTTP status code of the
status code has three numbers, the first number of defined categories of response, is divided into five categories:

1xx: instructions - indicates that the request has been received, continue processing
2xx: Success - indicates that the request has been successfully received, understood, accepted
3xx: Redirection - to fulfill the request must go a step further
4xx: Client Error - request a syntax error or a request can not be achieved
5xx: server-side error - the server failed to achieve a legitimate request
common status codes:

200 OK // client request was successful
400 Bad Request // client requests a syntax error, can not be understood by the server
401 Unauthorized // request is not authorized, the status code must be used with the WWW-Authenticate header field
403 Forbidden // server receives the request, but refused to provide service
404 not Found // requested resource does not exist, eg: enter the wrong the URL of
500 Internal server error // server error occurred unexpected
request 503 server unavailable // server is currently unable to process client after a period of time may return to normal
more state code http://www.runoob.com/http/http-status-codes.html

. 9, HTTP request method
according to the HTTP standard, HTTP request can use several request methods.
HTTP1.0 request defines three methods: GET, POST, and HEAD method.
HTTP1.1 five new request methods: OPTIONS, PUT, DELETE, TRACE, and CONNECT method.

GET request to the specified page information, and return the entity body.
HEAD similar get request, but the response is not returned in the specific content, for obtaining the header
POST submit data processing request to the specified resource (e.g., file submission form or upload). Data contained in the request body. POST request may result in a revision to establish and / or existing resources to new resources.
PUT replace specific content of the document data transmitted to the client from the server.
DELETE requests the server to delete the specified page.
CONNECT HTTP / 1.1 protocol can be reserved for connection to the proxy server pipeline mode.
OPTIONS allows the client to view server performance.
TRACE echo server receives the request, mainly for testing or diagnosis.
HTTP works
HTTP protocol defines how Web clients request Web pages from the Web server and the server how to transfer a Web page to the client. HTTP protocol uses a request / response model. The client sends the server a request packet, the method comprising the requested request packet, URL, protocol version, and requested data request header. A server response status line, including the contents of the protocol version response, success or error code, the server information, the response header and the response data.

10, the following is a step of HTTP request / response:

1, the client connects to the Web server
a HTTP client, typically a browser, Web server with HTTP port (default is 80) to establish a TCP socket connection. For example, http: //www.oakcms.cn.

2, an HTTP request
sent by a TCP socket text, client request message to the Web server, a request packet by the request line, request headers, blank lines, and 4 parts request data.

3, the server accepts the request and returns an HTTP response to
the Web server resolution request, the positioning request resources. The copy of the resource server writes a TCP socket, read by the client-side. A response line from the state, in response to the head, and blank lines in response to data 4 parts.

4, releasable connection TCP connection
when connection mode is close, the server closes the TCP connection, the client passive close the connection, releasing the TCP connection; if the connection mode Keepalive, then the connection will be maintained for a period of time, you can continue to receive within the time request;

5, the client browser parses the HTML content
client browser status line resolved first, to see that the request is successful status code. Then parse each response header, the response header to inform the character set of HTML documents and document several bytes. The client browser reads the HTML response data, formatted according to its HTML syntax, and displayed in the browser window.

For example: Type the URL in the browser address bar, then press Enter to go through the following process:

POST请求
POST / HTTP/1.1
Host: www.wrox.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6)
Gecko/20050225 Firefox/1.0.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 40
Connection: Keep-Alive

name = Professional% 20Ajax & publisher = Wiley
after 1, GET submitted, the request data is attached to the URL (that is, the data is placed into the HTTP protocol header), to divide the URL and transmit data, a plurality of parameters & connect; for example:? login .action? name = hyddd & password = idontknow & verify =% E4% BD% A0% E5% A5% BD. If the data is in English letters / numbers, as it is transmitted, if the space is converted to +, if Chinese / other characters, the string directly BASE64 encryption, obtained as:% E4% BD% A0% E5% A5% BD, where XX XX% for the symbols in the ASCII hexadecimal representation.

POST submission: submit the data packet is placed in the body of the HTTP packet. Red lettering is the actual data transmission in the above example

Therefore, the GET data submitted will be displayed in the address bar out, and POST submission, the address bar will not change
2, the size of the transmission of data: First statement: HTTP protocol does not limit the size of the transfer data, HTTP protocol specification nor did URL length limit.

Exists in the actual development restrictions are:

GET: has a specific browser and server URL length limit, e.g. IE URL length limit is 2083 bytes (2K + 35). For other browsers, such as Netscape, FireFox, etc., in theory, there is no length limit, that limit depends on operating system support.

So for the time GET submission, data transmission will be restricted URL length.

POST: Because not pass through the URL value, in theory, unlimited data. However, the actual requirements of each WEB server will submit data on post size limit, Apache, IIS6 has its own configuration.

3, security

GET POST of the security safe than others. For example: The GET to submit data, user name and password in clear text appears on the URL, because (1) the login page is likely to be browser cache; (2) others to view your browser history, so others can get your account number and password, in addition, use GET to submit data also may cause Cross-site request forgery attack

4, Http get, post, soap protocol is running on the http

(1) get: Request parameter is the additional sequence as a key / value pair (query string) to the URL on
the length of the query string and a web browser by a web server limits (e.g. IE supports up to 2048 characters), not suitable for transmission of large data sets at the same time, it is not safe

(2) post: request parameter in a different part of the http header transmission (named entity body), this part of the form used to transmit information, Content-type must be set: application / x-www-form- urlencoded . post designed to support the user on the web form field, which parameters are used as key / value pairs transmitted.
However: it does not support complex data types, because there is no post rules define the semantics and configuration of data transmission.

(3) soap: http post is a special version, following a special message format xml
Content-type to: text / xml xml can be of any data.

Http protocol defines a number of ways to interact with the server, there are four basic kinds, namely GET, POST, PUT, DELETE. URL address is used to describe a resource on a network, and in HTTP GET, POST, PUT, DELETE corresponding to this resource check, change, add, delete four operations. Our most common is the GET and POST. GET is generally used to get / query resource information, and POST are generally used to update resource information.

We look at the difference between GET and POST

Body GET data is placed after the submitted URL to? URL and transmit the divided data, is connected to between & parameter, such as EditPosts.aspx? Name = test1 & id = 123456. POST method is the data submitted in a HTTP packet .

GET submitted the data size is limited (because the browser restrictions on the length of the URL), and the data submitted by the POST method is not limited.

GET requires the use Request.QueryString to get the value of a variable, while the POST method to get the value of a variable by Request.Form.

Submit a GET data, it will bring security problems, such as a login page when submitting data via GET, the user name and password will appear in the URL, if the page can be cached or others can access this machine, you can from history record obtain the user ID and password.

Reference article:
https://tools.ietf.org/html/rfc2616
https://www.cnblogs.com/ranyonsue/p/5984001.html
recommend reading the article
https://blog.csdn.net/aliujiujiang/article/ the Details / 81,088,317
https://mp.weixin.qq.com/s/27zpNIGhVbx-on9FDs_6dw?
https://www.cnblogs.com/Mairr/p/8085850.html
https://blog.csdn.net/qq_21792169/ article / details / 56012789

Guess you like

Origin www.cnblogs.com/qianxiaoruofeng/p/11489837.html