HTTP Introduction
HTTP is a protocol belonging to the object-oriented application layer, due to its simple, fast way for distributed hypermedia information system. It is proposed in 1990, after several years of use and development, has been continuously improved and expanded.
The main characteristics of the HTTP protocol can be summarized as follows:
1. Supports client / server model.
2. simple and fast: a customer service request to the server, instead of sending the request method and path. Request method commonly used GET, HEAD, POST. Each method provides a different type of client contacts the server. Due to the simple HTTP protocol, HTTP server makes the program a small scale, so the communication is very fast.
3. Flexible: the HTTP allows the transmission of any type of data object. It is the type of transmission being marked by Content-Type.
4. No connection: Meaning No limitation is attached only one request per connection. After the server processes client requests and receives the customer's response, i.e., disconnected. In this way it can save transmission time.
5. stateless: HTTP protocol is stateless protocol. No state is no protocol for transaction processing and memory. If the lack of state means that the subsequent processing required in front of the information, it must be retransmitted, which may result in the amount of data transmitted for each connection is increased. On the other hand, when it does not require previous information in response to a faster server.
Http request
Editing a form.html form page, as follows:
Click on the submit button, capture the following:
1) Request line
Request mode: POST, GET
Resources requested: /DemoEE/form.html
Protocol version: HTTP / 1.1
HTTP / 1.0, the transmission request, to create a connection, to obtain a web resource is disconnected.
HTTP / 1.1, the transmission request, to create a connection, a plurality of web resources, remain connected.
2) request header
Request header is sent to the client some information about the server using key-value pairs representing key: value
Common request headers |
描述 (红色掌握,其他了解) |
Referer |
浏览器通知服务器,当前请求来自何处。如果是直接访问,则不会有这个头。常用于:防盗链 |
If-Modified-Since |
浏览器通知服务器,本地缓存的最后变更时间。与另一个响应头组合控制浏览器页面的缓存。 |
Cookie |
与会话有关技术,用于存放浏览器缓存的cookie信息。 |
User-Agent |
浏览器通知服务器,客户端浏览器与操作系统相关信息 |
Connection |
保持连接状态。Keep-Alive 连接中,close 已关闭 |
Host |
请求的服务器主机名 |
Content-Length |
请求体的长度 |
Content-Type |
如果是POST请求,会有这个头,默认值为application/x-www-form-urlencoded,表示请求体内容使用url编码 |
Accept: |
浏览器可支持的MIME类型。文件类型的一种描述方式。 MIME格式:大类型/小类型[;参数] 例如: text/html ,html文件 text/css,css文件 text/javascript,js文件 image/*,所有图片文件 |
Accept-Encoding |
浏览器通知服务器,浏览器支持的数据压缩格式。如:GZIP压缩 |
Accept-Language |
浏览器通知服务器,浏览器支持的语言。各国语言(国际化i18n) |
3)请求体
当请求方式是post时,请求体会有请求的参数,格式如下:
username=zhangsan&password=123
如果请求方式为get,那么请求参数不会出现在请求体中,会拼接在url地址后s
http://localhost:8080...?username=zhangsan&password=123