前言
原文地址:https://blog.csdn.net/nimasike/article/details/81122784
http連接
短連接
定義:http頭不包含Connection: Keep-Alive
socket讀取數據值返回-1者標記為結束
長連接
定義:http頭包含Connection: Keep-Alive
http協議結構
頭
頭結束符定義:包含這"\r\n\r\n" 四個字節是指頭結束
如果頭數據里包含Content-Length: x 就讀取x字節數據,知道http響應數據的長度為x
如果頭數據里不包含Content-Length: x 類型為Transfer-Encoding: chunked 說明響應數據的長度不固定,結束符已"\r\n0\r\n"這5個字節為結束符
body
http協議數據響應的內容
流程圖
wireshark抓包解析