HTTP Protocol Introduction
I. HTTP protocol:
HTTP is short for hypertext transfer protocol (hypertext transfer protocol). It is an application layer protocol of TCP/IP protocol, used to define the process of data exchange between WEB browsers and WEB servers.
The HTTP protocol is based on the Request Response model. A request corresponds to a response. A request can only be sent from a client, and the server can only passively wait for the request to respond.
Differences between HTTP1.0 and HTTP1.1: In HTTP1.0, only one web resource can be obtained after the client establishes a connection with the web server. HTTP1.1 allows the client to establish a connection with the web server, obtain multiple web resources from a single connection.
Ii. HTTP request:
After the client connects to the server, it requests a web resource from the server, which is called an HTTP request sent by the client to the server. A complete HTTP request includes the following content: A request line, several request headers, and entity content.
Example:
GET/books/java.html HTTP/1.1
Accept :*/*
Accept-Language: en-us
Connection: Keep-Alive
Host: localhost
Referer: http: // localhost/links. asp
User-Agent: Mozilla/4.0
Accept-Encoding: gzip, deflate
Request Line
GET/books/java.html HTTP/1.1
Request Methods: Seven request methods: POST, GET, HEAD, OPTIONS, DELETE, TRACE, PUT
In actual use: POST/GET
The difference between the GET request method and the post request is that the request parameters are different in the transmission process.
If a GET request is submitted, the request parameters will be appended to the request URL and taken to the server as part of the request address. The size of data that can be transmitted is generally not allowed to exceed 1 K.
If a POST request is submitted, the request parameters are transmitted in the object content of the http request. The data transmitted in this way has no size limit.
When using form to submit data, form indicates that a clear declaration must be submitted using POST. This is the request parameter or POST submission.
In addition, all request parameters are submitted by GET.
Several request headers-Message Headers
Accept :*/*
Accept-Charset: ISO-8859-1
Accept-Encoding: gzip, compress
Accept-Language: en-us, zh-cn
Host: www.it315.org: 80
If-Modified-Since: Tue, 11 Jul 2000 18:23:51 GMT
Referer: http://www.it315.org/index.jsp
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)
Cookie:
Connection: close/Keep-Alive
Date: Tue, 11 Jul 2000 18:23:51 GMT
Iii. HTTP response
An HTTP response represents the data that the server sends back to the client. It includes a status line, several response headers (message headers), and entity content.
Status line: HTTP/1.1 200 OK Protocol version status code reason description <CRLF>
Status Code -- code used to indicate the processing result of this request
200 indicates that the request is successfully received and the entire process has been completed.
302 objects moved
304/307 unmodified/Temporary redirection
404 client request Error
500 server errors
Response Headers
Location: http://www.it315.org/index.jsp
Server: apache tomcat
Content-Encoding: gzip
Content-Length: 80
Content-Language: zh-cn
Content-Type: text/html; charset = GB2312
Last-Modified: Tue, 11 Jul 2000 18:23:51 GMT
Refresh: 1, url = http://www.it315.org
Content-Disposition: attachment?filename=aaa.zip
Transfer-Encoding: chunked
Set-Cookie: SS = Q0 = 5Lb_nQ; path =/search
ETag: W/"83794-1208174400000"
Expires:-1 ---- notifies the browser whether to cache the current resource. If the header value is in milliseconds, it notifies the browser to cache the resource to the specified time point, if the value is 0 or-1, the browser is notified to disable caching.
Cache-Control: no-cache -- notifies the browser whether to Cache Resources
Pragma: no-cache -- notifies the browser whether to cache Resources
The reason why the three headers are a function is the historical reasons. Different browsers have different support for the three headers. Generally, these three headers must be used at the same time to ensure that different browsers can control the cache function.
Connection: close/Keep-Alive
Date: Tue, 11 Jul 2000 18:23:51 GMT