HTTP request報文結(jié)構(gòu)是怎樣的
首行是Request-Line包括:請求方法,請求URI,協(xié)議版本,CRLF
首行之后是若干行請求頭,包括general-header,request-header或者entity-header,每個一行以CRLF結(jié)束
請求頭和消息實體之間有一個CRLF分隔
根據(jù)實際請求需要可能包含一個消息實體 一個請求報文例子如下:
GET /Protocols/rfc2616/rfc2616-sec5.html HTTP/1.1
Host: www.w3.org
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36
Referer: https://www.google.com.hk/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: zh-CN,zh;q=0.8,en;q=0.6
Cookie: authorstyle=yes
If-None-Match: "2cc8-3e3073913b100"
If-Modified-Since: Wed, 01 Sep 2004 13:24:52 GMT
name=qiu&age=25
HTTP response報文結(jié)構(gòu)是怎樣的
首行是狀態(tài)行包括:HTTP版本,狀態(tài)碼,狀態(tài)描述,后面跟一個CRLF
首行之后是若干行響應(yīng)頭,包括:通用頭部,響應(yīng)頭部,實體頭部
響應(yīng)頭部和響應(yīng)實體之間用一個CRLF空行分隔
最后是一個可能的消息實體 響應(yīng)報文例子如下:
HTTP/1.1 200 OK
Date: Tue, 08 Jul 2014 05:28:43 GMT
Server: Apache/2
Last-Modified: Wed, 01 Sep 2004 13:24:52 GMT
ETag: "40d7-3e3073913b100"
Accept-Ranges: bytes
Content-Length: 16599
Cache-Control: max-age=21600
Expires: Tue, 08 Jul 2014 11:28:43 GMT
P3P: policyref="http://www.w3.org/2001/05/P3P/p3p.xml"
Content-Type: text/html; charset=iso-8859-1
{"name": "qiu", "age": 25}