æ¬äººè·webæ ç¼ï¼ä»æ¥æ²¡ææ³å»å¦httpï¼ç°å¨çæ¥ï¼å¦å¦ä¹æ¯æçæ 害ï¼æ»ä¼è¦ç¨çç¹æ»´ã
RFCè§è¿éï¼Â https://www.ietf.org/rfc/rfc2616.txtÂ
0. URIæ ¼å¼Â
ããhttp://host[:port][abs_path]Â
1. Message Type  (Request/Responseï¼
两ç§ç±»åæ ¼å¼ç»ä¸ï¼é½å
æ¬ä¸é¨åï¼å¤å ä¸ä¸ªç©ºè¡,æ ¼å¼å¦ä¸ï¼
start-line (request-line/status-line)
*(message-header CRLF)
[ message-body ]
 2.Start-Line:
(request) Request-Line = Method Request-URI HTTP-Version
ããããGET 请æ±è·å Request-URI ææ è¯çèµæº ããããPOST å¨ Request-URI ææ è¯çèµæºåéå æ°çæ°æ®ï¼éå¹çï¼ ããããHEAD 请æ±è·åç± Request-URI ææ è¯çèµæºçååºæ¶æ¯æ¥å¤´ ããããPUT 请æ±æå¡å¨åå¨ä¸ä¸ªèµæºï¼å¹¶ç¨ Request-URI ä½ä¸ºå ¶æ è¯ (å¹ç) ããããDELETE 请æ±æå¡å¨å é¤ Request-URI ææ è¯çèµæº ããããTRACE 请æ±æå¡å¨åéæ¶å°ç请æ±ä¿¡æ¯ï¼ä¸»è¦ç¨äºæµè¯æè¯æ ããããCONNECT ä¿çå°æ¥ä½¿ç¨ ããããOPTIONS 请æ±æ¥è¯¢æå¡å¨çæ§è½ï¼æè æ¥è¯¢ä¸èµæºç¸å ³çé项åéæ±ï¼ ãããããããã  ç¨æ¥è·åæ´å¤æå¡å¨ç«¯çä¿¡æ¯ï¼æ¯ä¸ä¸ªä¸åºè¯¥å¯¹æå¡å¨æ°æ®é æå½±åçæ¹æ³ã ãããã ãããã注ï¼å¦æä¸ä¸ªæ¹æ³éå¤æ§è¡å¤æ¬¡ï¼äº§ççæææ¯ä¸æ ·çï¼é£å°±æ¯å¹ç(idempotent)çã ãããããã请æ±æ°æ®ä¸å¨GETæ¹æ³ä¸ä½¿ç¨ï¼èæ¯å¨POSTæ¹æ³ä¸ä½¿ç¨ã ããããããPOSTæ¹æ³éç¨äºéè¦å®¢æ·å¡«å表åçåºåã ããããããä¸è¯·æ±æ°æ®ç¸å ³çæ常使ç¨ç请æ±å¤´æ¯Content-TypeåContent-Lengthã
(response) Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
ããç¶æ代ç ç±ä¸ä½æ°åç»æï¼ç¬¬ä¸ä¸ªæ°åå®ä¹äºååºçç±»å«ï¼ä¸æäºç§å¯è½åå¼ã
ãã1xxï¼æ示信æ¯--表示请æ±å·²æ¥æ¶ï¼ç»§ç»å¤çã
ãã2xxï¼æå--表示请æ±å·²è¢«æåæ¥æ¶ãç解ãæ¥åã
ãã3xxï¼éå®å--è¦å®æ请æ±å¿ é¡»è¿è¡æ´è¿ä¸æ¥çæä½ã
ãã4xxï¼å®¢æ·ç«¯é误--请æ±æè¯æ³é误æ请æ±æ æ³å®ç°ã
ãã5xxï¼æå¡å¨ç«¯é误--æå¡å¨æªè½å®ç°åæ³ç请æ±ã
ãã常è§ç¶æ代ç ãç¶ææè¿°ç说æå¦ä¸ã
ãã200 OKï¼å®¢æ·ç«¯è¯·æ±æåã
ãã400 Bad Requestï¼å®¢æ·ç«¯è¯·æ±æè¯æ³é误ï¼ä¸è½è¢«æå¡å¨æç解ã
ãã401 Unauthorizedï¼è¯·æ±æªç»ææï¼è¿ä¸ªç¶æ代ç å¿ é¡»åWWW-Authenticateæ¥å¤´åä¸èµ·ä½¿ç¨ã
ãã403 Forbiddenï¼æå¡å¨æ¶å°è¯·æ±ï¼ä½æ¯æç»æä¾æå¡ã
ãã404 Not Foundï¼è¯·æ±èµæºä¸åå¨ï¼ä¸¾ä¸ªä¾åï¼è¾å ¥äºé误çURLã
ãã500 Internal Server Errorï¼æå¡å¨åçä¸å¯é¢æçé误ã
ãã503 Server Unavailableï¼æå¡å¨å½åä¸è½å¤ç客æ·ç«¯ç请æ±ï¼ä¸æ®µæ¶é´åå¯è½æ¢å¤æ£å¸¸ï¼
ãã举个ä¾åï¼HTTP/1.1 200 OKï¼CRLFï¼ã
ããStatus-Code =
ãã"100" ; Section 10.1.1: Continue
ãã| "101" ; Section 10.1.2: Switching Protocols
ãã| "200" ; Section 10.2.1: OK
ãã| "201" ; Section 10.2.2: Created
ãã| "202" ; Section 10.2.3: Accepted
ãã| "203" ; Section 10.2.4: Non-Authoritative Information
ãã| "204" ; Section 10.2.5: No Content
ãã| "205" ; Section 10.2.6: Reset Content
ãã| "206" ; Section 10.2.7: Partial Content
ãã| "300" ; Section 10.3.1: Multiple Choices
ãã| "301" ; Section 10.3.2: Moved Permanently
ãã| "302" ; Section 10.3.3: Found
ãã| "303" ; Section 10.3.4: See Other
ãã| "304" ; Section 10.3.5: Not Modified
ãã| "305" ; Section 10.3.6: Use Proxy
ãã| "307" ; Section 10.3.8: Temporary Redirect
ãã| "400" ; Section 10.4.1: Bad Request
ãã| "401" ; Section 10.4.2: Unauthorized
ãã| "402" ; Section 10.4.3: Payment Required
ãã| "403" ; Section 10.4.4: Forbidden
ãã| "404" ; Section 10.4.5: Not Found
ãã| "405" ; Section 10.4.6: Method Not Allowed
ãã| "406" ; Section 10.4.7: Not Acceptable
ãã| "407" ; Section 10.4.8: Proxy Authentication Required
ãã| "408" ; Section 10.4.9: Request Time-out
ãã| "409" ; Section 10.4.10: Conflict
ãã| "410" ; Section 10.4.11: Gone
ãã| "411" ; Section 10.4.12: Length Required
ãã| "412" ; Section 10.4.13: Precondition Failed
ãã| "413" ; Section 10.4.14: Request Entity Too Large
ãã| "414" ; Section 10.4.15: Request-URI Too Large
ãã| "415" ; Section 10.4.16: Unsupported Media Type
ãã| "416" ; Section 10.4.17: Requested range not satisfiable
ãã| "417" ; Section 10.4.18: Expectation Failed
ãã| "500" ; Section 10.5.1: Internal Server Error
ãã| "501" ; Section 10.5.2: Not Implemented
ãã| "502" ; Section 10.5.3: Bad Gateway
ãã| "503" ; Section 10.5.4: Service Unavailable
ãã| "504" ; Section 10.5.5: Gateway Time-out
ãã| "505" ; Section 10.5.6: HTTP Version not supported
3. Message-Header = field-name ":" [ field-value ]ã
general-header = Cache-Control ; Section 14.9
| Connection ; Section 14.10
| Date ; Section 14.18
| Pragma ; Section 14.32
| Trailer ; Section 14.40
| Transfer-Encoding ; Section 14.41
| Upgrade ; Section 14.42
| Via ; Section 14.45
| Warning ; Section 14.46
request-header = Accept ; Section 14.1
| Accept-Charset ; Section 14.2
| Accept-Encoding ; Section 14.3
| Accept-Language ; Section 14.4
| Authorization ; Section 14.8
| Expect ; Section 14.20
| From ; Section 14.22
| Host ; Section 14.23
| If-Match ; Section 14.24
| If-Modified-Since ; Section 14.25
| If-None-Match ; Section 14.26
| If-Range ; Section 14.27
| If-Unmodified-Since ; Section 14.28
| Max-Forwards ; Section 14.31
| Proxy-Authorization ; Section 14.34
| Range ; Section 14.35
| Referer ; Section 14.36
| TE ; Section 14.39
| User-Agent ; Section 14.43
response-header = Accept-Ranges ; Section 14.5
| Age ; Section 14.6
| ETag ; Section 14.19
| Location ; Section 14.30
| Proxy-Authenticate ; Section 14.33
| Retry-After ; Section 14.37
| Server ; Section 14.38
| Vary ; Section 14.44
| WWW-Authenticate ; Section 14.47
entity-header = Allow ; Section 14.7
| Content-Encoding ; Section 14.11
| Content-Language ; Section 14.12
| Content-Length ; Section 14.13
| Content-Location ; Section 14.14
| Content-MD5 ; Section 14.15
| Content-Range ; Section 14.16
| Content-Type ; Section 14.17
| Expires ; Section 14.21
| Last-Modified ; Section 14.29
| extension-header
Â
4.Message-Body (text, or encoded text)
ããentity-body = *OCTET
ããentity-body := Content-Encoding( Content-Type( data ) )
ããExample: parameter=value&also=another
5. Example
1) Get
å°åä¸â?âä¹åçé¨åå°±æ¯éè¿GETåéç请æ±æ°æ®ï¼æ们å¯ä»¥å¨å°åæ ä¸æ¸ æ¥ççå°ï¼å个æ°æ®ä¹é´ç¨â&â符å·éå¼ãæ¾ç¶ï¼è¿ç§æ¹å¼ä¸éåä¼ éç§å¯æ°æ®ãå¦å¤ï¼ç±äºä¸åçæµè§å¨å¯¹å°åçå符éå¶ä¹ææä¸åï¼ä¸è¬æå¤åªè½è¯å«1024个å符ï¼æ以å¦æéè¦ä¼ é大éæ°æ®çæ¶åï¼ä¹ä¸éå使ç¨GETæ¹å¼ã GET /search?hl=zh-CN&source=hp&q=domety&aq=f&oq= HTTP/1.1 Â
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint,Â
application/msword, application/x-silverlight, application/x-shockwave-flash, */* Â
Referer: <a href="http://www.google.cn/">http://www.google.cn/</a> Â
Accept-Language: zh-cn Â
Accept-Encoding: gzip, deflate Â
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; TheWorld) Â
Host: <a href="http://www.google.cn">www.google.cn</a> Â
Connection: Keep-Alive Â
Cookie:Â PREF=ID=80a06da87be9ae3c:U=f7167333e2c3b714:NW=1:TM=1261551909:LM=1261551917:S=ybYcq2wpfefs4V9g;Â
NID=31=ojj8d-IygaEtSxLgaJmqSjVhCspkviJrB6omjamNrSm8lZhKy_yMfO2M4QMRKcH1g0iQv9u-2hfBW7bUFwVh7pGaRUb0RnHcJU37y-
FxlRugatx63JLv7CWMD6UB_O_r
2) Post
对äºä¸é¢æå°çä¸éå使ç¨GETæ¹å¼çæ åµï¼å¯ä»¥èè使ç¨POSTæ¹å¼ï¼ å 为使ç¨POSTæ¹æ³å¯ä»¥å 许客æ·ç«¯ç»æå¡å¨æä¾ä¿¡æ¯è¾å¤ã POSTæ¹æ³å°è¯·æ±åæ°å°è£ å¨HTTP请æ±æ°æ®ä¸ï¼ä»¥å称/å¼çå½¢å¼åºç°ï¼å¯ä»¥ä¼ è¾å¤§éæ°æ®ï¼ è¿æ ·POSTæ¹å¼å¯¹ä¼ éçæ°æ®å¤§å°æ²¡æéå¶ï¼èä¸ä¹ä¸ä¼æ¾ç¤ºå¨URLä¸ã è¿ä»¥ä¸é¢çæç´¢domety为ä¾ï¼å¦æ使ç¨POSTæ¹å¼çè¯ï¼æ ¼å¼å¦ä¸ï¼ POST /search HTTP/1.1 Â
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint,Â
application/msword, application/x-silverlight, application/x-shockwave-flash, */* Â
Referer: <a href="http://www.google.cn/">http://www.google.cn/</a> Â
Accept-Language: zh-cn Â
Accept-Encoding: gzip, deflate Â
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; TheWorld) Â
Host: <a href="http://www.google.cn">www.google.cn</a> Â
Connection: Keep-Alive Â
Cookie:Â PREF=ID=80a06da87be9ae3c:U=f7167333e2c3b714:NW=1:TM=1261551909:LM=1261551917:S=ybYcq2wpfefs4V9g;Â
NID=31=ojj8d-IygaEtSxLgaJmqSjVhCspkviJrB6omjamNrSm8lZhKy_yMfO2M4QMRKcH1g0iQv9u-2hfBW7bUFwVh7pGaRUb0RnHcJU37y-
FxlRugatx63JLv7CWMD6UB_O_r Â
hl=zh-CN&source=hp&q=domety å¯ä»¥çå°ï¼POSTæ¹å¼è¯·æ±è¡ä¸ä¸å å«æ°æ®å符串ï¼è¿äºæ°æ®ä¿åå¨â请æ±å 容âé¨åï¼åæ°æ®ä¹é´ä¹æ¯ä½¿ç¨â&â符å·éå¼ã POSTæ¹å¼å¤§å¤ç¨äºé¡µé¢ç表åä¸ãå 为POSTä¹è½å®æGETçåè½ï¼å æ¤å¤æ°äººå¨è®¾è®¡è¡¨åçæ¶åä¸å¾é½ä½¿ç¨POSTæ¹å¼ï¼ å ¶å®è¿æ¯ä¸ä¸ªè¯¯åºãGETæ¹å¼ä¹æèªå·±çç¹ç¹åä¼å¿ï¼æ们åºè¯¥æ ¹æ®ä¸åçæ åµæ¥éæ©æ¯ä½¿ç¨GETè¿æ¯ä½¿ç¨POSTã   3) ä¸é¢ç»åºä¸ä¸ªHTTPååºæ¥æä¾å:
HTTP/1.1Â 200Â OK
Date: Sat, 31 Dec 2005 23:59:59 GMT
Content-Type:Â text/html;charset=ISO-8859-1
Content-Length:Â 122
ï¼htmlï¼
ï¼headï¼
ï¼titleï¼Wrox Homepageï¼/titleï¼
ï¼/headï¼
ï¼bodyï¼
ï¼!-- body goes here --ï¼
ï¼/bodyï¼
ï¼/htmlï¼
 Â
HTTP2.0çæ¹è¿ä¹å¤ï¼
HTTP2.0å°±æ¯å¨åºç¨å±(HTTP/2)åä¼ è¾å±(TCP or UDP)ä¹é´å¢å ä¸ä¸ªäºè¿å¶å帧å±ã
å¨äºè¿å¶å帧å±ä¸ï¼ HTTP/2 ä¼å°ææä¼ è¾çä¿¡æ¯åå²ä¸ºæ´å°çæ¶æ¯å帧ï¼frameï¼,并对å®ä»¬éç¨äºè¿å¶æ ¼å¼çç¼ç ï¼
å ¶ä¸ HTTP1.x çé¦é¨ä¿¡æ¯ä¼è¢«å°è£ å° HEADER frameï¼èç¸åºç Request Body åå°è£ å° DATA frame éé¢ã
æå ³é®çä¸ä¸ªå段æ¯Stream Identifier
转载äº:https://www.cnblogs.com/awiki/p/5520360.html