ä½ä¸ºä¸ä¸ªåå¦è ï¼æ¬æ¥ä»¥ä¸ºè¿äºTCP/IPãUDPåè®®ä» ä» æ¯æ åï¼ç¨å¾®äºè§£ä¸ä¸å°±è¡ï¼åæ¥åç°ï¼ä» ä» äºè§£å®å ¨ä¸å¤ã
Â
HTTPæ¥ææ两ç§ï¼è¯·æ±æ¥æï¼ååºæ¥æã
请æ±æ¥æ
Â
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:Â http://www.google.cn/Â
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:Â www.google.cnÂ
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
è§å¯åç°ï¼æ¥ææ¯ç¨æ®éçASCIIææ¬ä¹¦åãå ¶æ¬¡ï¼æ¥ææå¾å¤è¡ï¼æ¯è¡ç¨ä¸ä¸ªå车æ¢è¡ç¬¦ç»æãÂ
第ä¸è¡ï¼è¯·æ±è¡ï¼request lineï¼ï¼ç¬¬ä¸è¡åé¢çè¡ï¼ä¸ºé¦é¨è¡ï¼header lineï¼ãÂ
请æ±è¡âââââââââââââââ
GET /search?hl=zh-CN&source=hp&q=domety&aq=f&oq= HTTP/1.1
- 1
æ3个å段ï¼æ¹æ³å段ï¼URLå段ï¼HTTPåè®®çæ¬å段ãÂ
æ¹æ³å段ï¼GET,POST,HEAD,PUT,DELETEã
å½æµè§å¨è¯·æ±ä¸ä¸ªå¯¹è±¡æ¶ï¼ä½¿ç¨GETæ¹æ³ï¼å¨URLå段填å该对象çURLå°åãÂ
Â
ã
GET
æ常è§çä¸ç§è¯·æ±æ¹å¼ï¼å½å®¢æ·ç«¯è¦ä»æå¡å¨ä¸è¯»åææ¡£æ¶ï¼å½ç¹å»ç½é¡µä¸çé¾æ¥æè éè¿å¨æµè§å¨çå°åæ è¾å ¥ç½åæ¥æµè§ç½é¡µçï¼ä½¿ç¨çé½æ¯GETæ¹å¼ãGETæ¹æ³è¦æ±æå¡å¨å°URLå®ä½çèµæºæ¾å¨ååºæ¥æçæ°æ®é¨åï¼åéç»å®¢æ·ç«¯ã使ç¨GETæ¹æ³æ¶ï¼è¯·æ±åæ°å对åºçå¼éå å¨URLåé¢ï¼å©ç¨ä¸ä¸ªé®å·ï¼â?âï¼ä»£è¡¨URLçç»å°¾ä¸è¯·æ±åæ°çå¼å§ï¼ä¼ éåæ°é¿åº¦åéå¶ãä¾å¦ï¼/index.jsp?id=100&op=bind,è¿æ ·éè¿GETæ¹å¼ä¼ éçæ°æ®ç´æ¥è¡¨ç¤ºå¨å°åä¸ï¼æ以æ们å¯ä»¥æ请æ±ç»æ以é¾æ¥çå½¢å¼åéç»å¥½åã
POST
对äºä¸é¢æå°çä¸éå使ç¨GETæ¹å¼çæ åµï¼å¯ä»¥èè使ç¨POSTæ¹å¼ï¼å 为使ç¨POSTæ¹æ³å¯ä»¥å 许客æ·ç«¯ç»æå¡å¨æä¾ä¿¡æ¯è¾å¤ãPOSTæ¹æ³å°è¯·æ±åæ°å°è£ å¨HTTP请æ±æ°æ®ä¸ï¼ä»¥å称/å¼çå½¢å¼åºç°ï¼å¯ä»¥ä¼ è¾å¤§éæ°æ®ï¼è¿æ ·POSTæ¹å¼å¯¹ä¼ éçæ°æ®å¤§å°æ²¡æéå¶ï¼èä¸ä¹ä¸ä¼æ¾ç¤ºå¨URLä¸ã
Â
HEAD
HEADå°±åGETï¼åªä¸è¿æå¡ç«¯æ¥åå°HEAD请æ±ååªè¿åååºå¤´ï¼èä¸ä¼åéååºå 容ãå½æ们åªéè¦æ¥çæ个页é¢çç¶æçæ¶åï¼ä½¿ç¨HEADæ¯é常é«æçï¼å 为å¨ä¼ è¾çè¿ç¨ä¸çå»äºé¡µé¢å 容ã
ãé¦é¨è¡ââââââ-Â
é¦é¨è¡æä¾çä¿¡æ¯æ¯WEB代çç¼åæè¦æ±çã
Host: <a href="http://www.google.cn" target="_blank" rel="external nofollow" >www.google.cn</a>
- 1
å®ä¹äºç®æ æå¨ç主æºã
Connection: Keep-Alive
- 1
æµè§å¨åè¯æå¡å¨ä½¿ç¨æä¹ è¿æ¥ï¼ close å 使ç¨éæä¹ è¿æ¥ï¼å³è¦æ±æå¡å¨å¨åé请æ±ç对象åå°±å ³éè¿æ¥ï¼
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; TheWorld)
- 1
å®ä¹ç¨æ·ä»£çï¼å³åæå¡å¨åé请æ±çæµè§å¨ç±»åã Mozilla/4.0为Netscapeæµè§å¨ãå æ¤æå¡å¨å¯ä»¥æ£ç¡®å°ä¸ºä¸åç±»åçç¨æ·ä»£çå®é åéç¸åç对象ä¸åççæ¬ã
Accept-Language: zh-cn
- 1
表示ç¨æ·æ³å¾å°è¯¥å¯¹è±¡çè¯è¨çæ¬ï¼Â
ãããããããããããæ»ä¹ï¼HTTP请æ±æ¥æä¸æå¾å¤å¯éçé¦é¨è¡Â
- - - - - - - - -ä¸é¢çç请æ±æ¥æçéç¨æ ¼å¼Â
-Â
å¨é¦é¨è¡åæä¸ä¸ªâå®ä½ä¸»ä½âï¼entity bodyï¼ä½¿ç¨GETæ¹æ³æ¯å®ä½ä¸»ä½ä¸ºç©ºãÂ
客æ·æºé常å¨æ交表åæ¶ä½¿ç¨POSTæ¹æ³ï¼å®ä½ä¸»ä½ä¸å å«çå°±æ¯è¡¨åå段ä¸è¾å ¥çå¼Â
HEADæ¹æ³ç±»ä¼¼äºGETæ¹æ³ï¼å½æå¡å¨æ¶å°ä½¿ç¨HEADæ¹æ³ç请æ±æ¶ï¼ä¼ä½¿ç¨ä¸ä¸ªHTTPæ¥æè¿è¡ååºï¼ä½æ¯å¹¶ä¸æ¯è¿å请æ±å¯¹è±¡ãåºç¨ç¨åºå¼åè 常ç¨HEADæ¹æ³è¿è¡æ éè·è¸ªãÂ
PUTæ¹æ³å¸¸ä¸WEBåè¡å·¥å ·èå使ç¨ï¼ç¨æ·å©ç¨ä»å°å¯¹è±¡ä¸ä¼ å°æå®æå¡å¨çæå®è·¯å¾ï¼ç®å½ï¼ãä¹ç¨æ¥åæå¡å¨ä¸ä¼ 对象ãÂ
DELETEæ¹æ³ï¼åºç¨ç¨åºå¯å é¤WEBæå¡å¨ä¸ç对象ã
ååºæ¥æ
æ åâ-
HTTP/1.1 200 OK
Date: Sat, 31 Dec 2005 23:59:59 GMT
Connection: Keep-Alive
Content-Type: text/html;charset=ISO-8859-1
Content-Length: 122
ï¼htmlï¼
ï¼headï¼
ï¼titleï¼Wrox Homepageï¼/titleï¼
ï¼/headï¼
ï¼bodyï¼
ï¼!-- body goes here --ï¼
ï¼/bodyï¼
ï¼/htmlï¼
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
ååºæ¥æåæä¸ä¸ªé¨åï¼Â
åå§ç¶æè¡(status line)Â
é¦é¨è¡(header line)Â
å®ä½ä¸»é¢(entity body)Â
å®ä½ä¸»ä½é¨åæ¯æ¥æç主ä½ï¼å³ä»å å«äºææ请æ±ç对象æ¬èº«
ç¶æè¡æ3个å段ï¼åè®®çæ¬ï¼ç¶æç ï¼ç¸åºç¶æä¿¡æ¯ã
HTTP/1.1 200 OK
- 1
å¨è¿ä¸ªæ åä¸ï¼ç¶æè¡æ示æå¡å¨ä½¿ç¨çåè®®æ¯HTTP/1.1ï¼å¹¶ä¸ä¸åæ£å¸¸(æå¡å¨å·²æ¾å°å¹¶æ£å¨åéæ请æ±ç对象)
åççé¦é¨è¡ï¼
Connection: close
- 1
è¿ä¸ªé¦é¨è¡åè¯å®¢æ·æºå¨æ¥æåéå®åå ³éäºè¯¥TCPè¿æ¥ã
Date:â¦.é¦é¨è¡æ示æå¡å¨äº§ç并åé该ç¸åºæ¥æçæ¥æåæ¶é´ãè¿ä¸ªæ¶é´æ¯æå¡å¨ä»ä»çæ件系ç»ä¸æ£ç´¢å°è¯¥å¯¹è±¡ãæå ¥å°ååºæ¥æ并åéååºæ¥æçæ¶é´ãÂ
Server:é¦é¨è¡ 表æ该æ¥ææ¯ç±ä¸ä¸ªä»ä¹æå¡å¨äº§ççï¼ç±»ä¼¼äºè¯·æ±æ¥æä¸çUser-agent:é¦é¨è¡ .Â
Last-Modified:é¦é¨è¡ 表示对象å建ä¼æåä¿®æ¹çæ¥æåæ¶é´ï¼è¿ä¸ªé¦é¨è¡å¯¹å¯è½å¨å®¢æ·æºä¹å¯è½å¨ç½ç»ç¼åæå¡å¨ä¸ç对象ç¼åå¾éè¦ãÂ
Content-Length:é¦é¨è¡ 表æ被åé对象çåèæ°ãÂ
Content-Type:é¦é¨è¡ æ示äºå®ä½ä¸»ä½ä¸ç对象æ¶ä»ä¹ç±»åçææ¬å¦HTMLææ¬ï¼JSON对象ææ¬
âââââ ä¸é¢çç请æ±æ¥æéç¨æ ¼å¼ââ âÂ
Â
ä¸äºå¸¸è§çç¶æç ç¸å ³çè¯ï¼Â
200 OK ï¼è¯·æ±æåï¼ä¿¡æ¯å å«å¨è¿åçååºæ¥æä¸Â
301 Moved Permanently:请æ±ç对象已ç»è¢«æ°¸ä¹ 被转移äºï¼æ°çURLå®ä¹å¨ååºæ¥æçLocation:é¦é¨è¡ ä¸å®ä¹ã客æ·æºèªå¨ç¨æ°çURLè·å对象ãÂ
400 Bad Request:ä¸ä¸ªéç¨å·®é代ç ï¼è¯·æ±ä¸è½æå¡å¨ç解Â
404 Not Found:被请æ±çææ¡£ä¸å¨æå¡å¨ä¸Â
505 HTTP Version Not Supported:æå¡å¨ä¸æ¯æ请æ±æ¥æ使ç¨çHTTPçæ¬
å ³äºHTTP请æ±GETåPOSTçåºå«
Â
1.GETæ交ï¼è¯·æ±çæ°æ®ä¼éå¨URLä¹åï¼å°±æ¯ææ°æ®æ¾ç½®å¨HTTPå议头ï¼request-lineï¼ä¸ï¼ï¼ä»¥?åå²URLåä¼ è¾æ°æ®ï¼å¤ä¸ªåæ°ç¨&è¿æ¥;ä¾å¦ï¼login.action?name=hyddd&password=idontknow&verify=%E4%BD%A0 %E5%A5%BDãå¦ææ°æ®æ¯è±æåæ¯/æ°åï¼åæ ·åéï¼å¦ææ¯ç©ºæ ¼ï¼è½¬æ¢ä¸º+ï¼å¦ææ¯ä¸æ/å ¶ä»å符ï¼åç´æ¥æå符串ç¨BASE64å å¯ï¼å¾åºå¦ï¼ %E4%BD%A0%E5%A5%BDï¼å ¶ä¸ï¼ XXä¸çXX为该符å·ä»¥16è¿å¶è¡¨ç¤ºçASCIIã
  POSTæ交ï¼ææ交çæ°æ®æ¾ç½®å¨æ¯HTTPå çå ä½ï¼request-bodyï¼ä¸ãä¸æ示ä¾ä¸çº¢è²åä½æ æçå°±æ¯å®é çä¼ è¾æ°æ®
  å æ¤ï¼GETæ交çæ°æ®ä¼å¨å°åæ ä¸æ¾ç¤ºåºæ¥ï¼èPOSTæ交ï¼å°åæ ä¸ä¼æ¹å
Â
2.ä¼ è¾æ°æ®ç大å°ï¼
  é¦å 声æ,HTTPå议没æå¯¹ä¼ è¾çæ°æ®å¤§å°è¿è¡éå¶ï¼HTTPåè®®è§èä¹æ²¡æ对URLé¿åº¦è¿è¡éå¶ã èå¨å®é å¼åä¸åå¨çéå¶ä¸»è¦æï¼
  GET:ç¹å®æµè§å¨åæå¡å¨å¯¹URLé¿åº¦æéå¶ï¼ä¾å¦IE对URLé¿åº¦çéå¶æ¯2083åè(2K+35)ã对äºå ¶ä»æµè§å¨ï¼å¦NetscapeãFireFoxçï¼ç论ä¸æ²¡æé¿åº¦éå¶ï¼å ¶éå¶åå³äºæä½ç³»ç»çæ¯æã
   å æ¤å¯¹äºGETæ交æ¶ï¼ä¼ è¾æ°æ®å°±ä¼åå°URLé¿åº¦çéå¶ã
   POST:ç±äºä¸æ¯éè¿URLä¼ å¼ï¼ç论ä¸æ°æ®ä¸åéãä½å®é å个WEBæå¡å¨ä¼è§å®å¯¹postæ交æ°æ®å¤§å°è¿è¡éå¶ï¼ApacheãIIS6é½æåèªçé ç½®ã
Â
3.å®å ¨æ§ï¼
    POSTçå®å ¨æ§è¦æ¯GETçå®å ¨æ§é«ã注æï¼è¿éæ说çå®å ¨æ§åä¸é¢GETæå°çâå®å ¨âä¸æ¯å个æ¦å¿µãä¸é¢âå®å ¨âçå«ä¹ä» ä» æ¯ä¸ä½æ°æ®ä¿®æ¹ï¼èè¿éå®å ¨çå«ä¹æ¯çæ£çSecurityçå«ä¹ï¼æ¯å¦ï¼éè¿GETæ交æ°æ®ï¼ç¨æ·ååå¯ç å°ææåºç°å¨URLä¸ï¼å 为(1)ç»å½é¡µé¢æå¯è½è¢«æµè§å¨ç¼åï¼ (2)å ¶ä»äººæ¥çæµè§å¨çåå²çºªå½ï¼é£ä¹å«äººå°±å¯ä»¥æ¿å°ä½ çè´¦å·åå¯ç äºï¼
https://blog.csdn.net/qq_26927285/article/details/54427482