Reprint Address: http://blog.jobbole.com/84429/
TCP HTTP UDP:
is the communication protocol, that is, the rules of communication, only the two parties in accordance with this rule "speak", the other party can understand or serve.
The relationship between TCP HTTP UDP three:
TCP/IP is a protocol group, which can be divided into four levels: network interface layer, network layer, Transport layer and application layer.
At the network layer are IP protocols, ICMP protocols, ARP protocols, RARP protocols, and BOOTP protocols.
There are TCP protocols and UDP protocols in the transport layer.
In the application layer, there are FTP, HTTP, TELNET, SMTP, DNS and other protocols.
Therefore, HTTP itself is a protocol that transmits hypertext to a local browser from a Web server.
Socket
This is to achieve the above communication process to establish a communication pipeline, its real representative is a client and server side of a communication process, the two sides of the process through the socket to communicate, and the rules of communication using the specified protocol. Socket is just a connection mode, not protocol, TCP, UDP, simple (although inaccurate) is the two most basic protocol, many other protocols are based on these two protocols, such as HTTP is based on TCP,. You can create a TCP connection with a socket, or you can create a UDP connection. This means that a socket can be used to create a connection to any protocol, because other protocols are based on this.
Here's a look at the protocols that are closely related to our Internet life: HTTP
What is Http Protocol
HTTP full name is Hypertext Transfer Protocal, that is: Hypertext Transfer Protocol, from 1990 onwards in the WWW widely used, is now the most widely used in the WWW protocol, HTTP is the application layer protocol, when you surf the Web page, Data is sent and received over the Internet through HTTP between the browser and the Web server. HTTP is a stateless protocol based on the request/response pattern. That's what we usually call request/response.
URL :
The URL (Uniform Resource Locator) address is used to describe a resource on a network with the following basic format
schema://host[:p ort#]/path/.../[?query-string][#anchor]
Scheme specifies the protocol used by the lower layer (for example: HTTP, HTTPS, FTP)
The IP address or domain name of the host HTTP server
The default port for the port# HTTP server is 80, in which case the lower number can be omitted. If you use a different port, you must specify, for example, http://www.cnblogs.com:8080/
Path to access resource
Query-string data sent to the HTTP server
anchor-Anchor
An example of a URL
Http://www.mywebsite.com/sj/test/test.aspx?name=sviergn&x=true#stuff
Schema:http
Host:www.mywebsite.com
Path:/sj/test/test.aspx
Query String:name=sviergn&x=true
Anchor:stuff
HTTP of the Request/response :
Look at the structure of the request message, the request message is divided into 3 parts
The first part is called Request line,
The second part is called the request header,
The third part is body. There is a blank line between the header and the body,
Structure such as
The method in the first line represents the request methods, such as "POST", "GET", Path-to-resoure represents the requested resource, and Http/version-number represents the version number of the Http protocol
When the "GET" method is used, the body is empty
For example, we open the Blog Garden home page request as follows
GET http://www.cnblogs.com/HTTP/1.1
Host:www.cnblogs.com
Abstract things, difficult to understand, the old feeling is virtual, the so-called seeing is real, actually see things, we can understand and remember. Today we use Fiddler, actually look at the request and response.
Below we open fiddler capture a blog Park login request and then analyze its structure, in the Inspectors tab under the raw way to see the complete request message,
Such as
Accept
Role: The type of media that can be accepted by the browser side,
For example: accept:text/html represents the type of server postback that the browser can accept as text/html, which is what we often call HTML documents,
If the server cannot return data of type text/html, the server should return a 406 error (non acceptable)
Wildcard * represents any type
For example, Accept: */* on behalf of the browser can handle all types, (the general browser to the server is the issue of this)
Referer:
Role: The server that provides the context information for the request tells the server which link I have received from, such as linking to a friend from my home page, and his server is able to count the number of users who clicked the link on my page every day from the HTTP referer to visit his website.
Example: REFERER:HTTP://TRANSLATE.GOOGLE.CN/?HL=ZH-CN&TAB=WT
Accept-language
Role: The browser affirms the language it receives.
Language and Character set differences: Chinese is a language, Chinese has a variety of character sets, such as BIG5,GB2312,GBK and so on;
Example: accept-language:en-us
Content-type
Role:
Example: content-type:application/x-www-form-urlencoded
accept-encoding :
Function: The browser declares itself to receive the encoding method, usually specifies the compression method, whether compression is supported, what compression method is supported (Gzip,deflate), (note: This is not a character encoding);
Example: Accept-encoding:gzip, deflate
User-agent
Role: tells the HTTP server which client uses the name and version of the operating system and browser.
When we go online to the forum, often see some welcome information, which lists the name and version of your operating system, the name and version of the browser you are using, which often makes a lot of people feel very magical, in fact, The server application obtains this information from the User-agent request header domain user-agent The request header domain allows the client to tell the server about its operating system, browser, and other properties.
For example: user-agent:mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; trident/4.0; CIBA;. NET CLR 2.0.50727;. NET CLR 3.0.4506.2152;. NET CLR 3.5.30729;. net4.0c; infopath.2;. NET4.0E)
Connection
Example: connection:keep-alive when a Web page opens, the TCP connection between the client and the server for transmitting HTTP data does not close, and if the client accesses the Web page on the server again, it will continue to use the established connection
For example: Connection:close represents the completion of a request, the TCP connection between the client and the server for transmitting HTTP data is turned off, and the TCP connection needs to be re-established when the client sends the request again.
Content-length
Role: The length of the data sent to the HTTP server.
Example: content-length:38
Host(the header field is required when the request is sent)
Role: The request header domain is used primarily to specify the Internet host and port number of the requested resource, which is typically extracted from the HTTP URL
For example: We entered in the browser: http://www.guet.edu.cn/index.html
In the request message sent by the browser, the host Request header field is included, as follows:
host:http://www.guet.edu.cn
The default port number 80 is used here, and if a port number is specified, it becomes: Host: Specify port number
Pragma
Role: Prevent the page from being cached, in the http/1.1 version, it is identical to the Cache-control:no-cache function
Pargma has only one usage, for example: Pragma:no-cache
Cookies:
Role: The most important header, the value of the cookie is sent to the HTTP server
Accept-charset
Role: The browser affirms its own received character set, this is the various character sets and character encodings described earlier in this article, such as gb2312,utf-8 (usually we say CharSet includes the corresponding character encoding scheme);
Let's look at the structure of the response message, which is basically the same as the structure of the request message. Also divided into three parts
The first part is called Response line,
The second part is called response header,
The third part is body. There is also a blank line between the header and the body.
Structure such as
Http/version-number represents the version number of the HTTP protocol, Status-code and message, see the detailed explanation of the next section [Status code].
We use Fiddler to capture a blog home response then analyze its structure, in the Inspectors tab under the raw way can see the full response message, such as
Cache-control
Role: This is a very important rule. This is used to specify the caching mechanism that response-request follows. Each instruction has the following meanings
Cache-control:public can be cached by any cache ()
Cache-control:private content is cached only in the private cache
Cache-control:no-cache All content is not cached
There are other uses, I do not understand the meaning, please refer to other information
Content-type
Role: The Web server tells the browser the type and character set of the object it responds to.
For example:
content-type:text/html; Charset=utf-8
content-type:text/html;charset=gb2312
Content-type:image/jpeg
Expires
Role: The browser will use the local cache for the specified expiration period
For example: Expires:tue, 2022 11:35:14 GMT
Last-modified:
Role: Used to indicate the last modification date and time of the resource. (See examples of if-modified-since in the section)
Example: last-modified:wed, Dec 09:09:10 GMT
Server:
Function: Indicates the software information of the HTTP server
Example: server:microsoft-iis/7.5
X-aspnet-version:
Role: If the Web site is developed with ASP, this header is used to represent the version of ASP.
Example: x-aspnet-version:4.0.30319
X-powered-by:
Role: Indicates what technology the site is developed with
Example: X-powered-by:asp.net
Connection
Example: connection:keep-alive when a Web page opens, the TCP connection between the client and the server for transmitting HTTP data does not close, and if the client accesses the Web page on the server again, it will continue to use the established connection
For example: Connection:close represents the completion of a request, the TCP connection between the client and the server for transmitting HTTP data is turned off, and the TCP connection needs to be re-established when the client sends the request again.
Content-length
Indicates the length of the entity body, expressed as a decimal number stored in bytes. In the process of data downlink, content-length the way to pre-cache all the data in the server, and then all the data peremptorily to the client.
Example: content-length:19847
Date
Role: The exact time and date of the message generation
Example: Date:sat, 11:35:14 GMT
HTTP of the Agreement Get and the Post
The HTTP protocol defines a number of ways to interact with the server, the most basic of which are 4, get,post,put,delete, respectively. A URL address is used to describe a resource on a network, and the Get, POST, PUT, delete in HTTP corresponds to the search for this resource, change, increase, delete 4 operations. Our most common is get and post. Get is typically used to get/query resource information, and post is typically used to update resource information.
Let's look at the difference between get and post
1. Get submitted data will be placed after the URL, to split the URL and transfer data, the parameters are connected with &, such as editposts.aspx?name=test1&id=123456. The Post method is to put the submitted data in the body of the HTTP packet.
2. The data size of the Get commit is limited (because the browser has a limit on the length of the URL), and there is no limit to the data submitted by the Post method.
3. The Get method needs to use Request.QueryString to get the value of the variable, and the post way to get the value of the variable by Request.Form, that is, get is passed through the address bar, and post is forms by the submission table.
4. The Get method submits the data, which brings security issues, such as a login page, when the data is submitted by get, the user name and password will appear on the URL, if the page can be cached or other people can access the machine, you can obtain the user's account and password from the history.
Communication protocols: HTTP, TCP, UDP