Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

图解HTTP之HTTP首部 #21

Open
chenxiaochun opened this issue Jun 2, 2017 · 0 comments
Open

图解HTTP之HTTP首部 #21

chenxiaochun opened this issue Jun 2, 2017 · 0 comments

Comments

@chenxiaochun
Copy link
Owner

chenxiaochun commented Jun 2, 2017

HTTP报文首部

HTTP协议的请求和响应报文中必定包含HTTP首部。首部内容为客户端和服务器分别处理请求和响应提供所需要的信息。

HTTP请求报文

由方法、URI、HTTP版本、HTTP首部字段等部分构成。

GET / HTTP/1.1
Host: jd.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/⇒ 20100101 Firefox/13.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,⇒ */*; q=0.8
Accept-Language: ja,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
If-Modified-Since: Fri, 31 Aug 2007 02:02:20 GMT
If-None-Match: "45bae1-16a-46d776ac"
Cache-Control: max-age=0

HTTP响应报文

由HTTP版本、状态码以及HTTP首部字段构成。

HTTP/1.1 304 Not Modified
Date: Thu, 07 Jun 2012 07:21:36 GMT
Server: Apache
Connection: close
Etag: "45bae1-16a-46d776ac"

HTTP首部字段

HTTP首部字段的作用

在客户端与服务器进行通信的过程中,起到传递重要信息的作用。可以给浏览器和服务器提供报文主体大小、所使用的语言、认证信息等内容。

HTTP首部字段结构

它是由首部字段名和字段值构成的,中间用冒号“:”分隔。

首部字段名: 字段值

例如:

Content-Type: text/html

另外,首部字段可以对应多个值,例如:

Keep-Alive: timeout=15, max=100

HTTP首部字段根据实际用途分为4种类型:通用首部字段、请求首部字段、响应首部字段、实体首部字段。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant