HTTP權威指南閱讀筆記三 HTTP報文

2021-09-06 12:11:18 字數 4512 閱讀 6852

報文的組成部分

報文由三部分組成:對報文進行描述的起始行(start line)、包含屬性的首部(header),以及可選的、包含資料的主體(body)部分。

請求報文格式

響應報文格式

http方法

主要的http方法有:

方法描述

是否包含主體

get從伺服器獲取乙份文件

否head

只從伺服器獲取文件的首部

否post

向伺服器傳送需要處理的資料

是put

將請求的主體部分儲存在伺服器上

是trace

對可能經過**伺服器傳送到伺服器上去的報文進行追蹤

否options

決定可以在伺服器上執行哪些方法

否delete

從伺服器上刪除乙份文件

否 另外,http1.1允許擴充套件規範中沒有的方法。

示例

js部分:

由於ajax中不可以直接發trace請求,所以這裡改為發get請求,然後在controller中作**發trace請求

btntrace.onclick = function

() btnoptions.onclick = function

() //

從xmlhttprequest中取出header及body資料

function

methodresult(xhr) ,

response = "",

results =;

header["status"] =xhr.status;

header["statustext"] =xhr.statustext;

header["cache-control"] = xhr.getresponseheader("cache-control");

header["content-type"] = xhr.getresponseheader("content-type");

header["allow"] = xhr.getresponseheader("allow");

header["content-encoding"] = xhr.getresponseheader("content-encoding");

header["vary"] = xhr.getresponseheader("vary");

header["server"] = xhr.getresponseheader("server");

header["date"] = xhr.getresponseheader("date");

header["content-length"] = xhr.getresponseheader("content-length");

for (var key in

header)

}headerresultnode.innerhtml = results.join("");

bodyresultnode.value =xhr.responsetext;

}頁面部分:

<

div>

<

input

type

="button"

id="btnget"

value

="get"

/>

<

input

type

="button"

id="btnpost"

value

="post"

/>

<

input

type

="button"

id="btnput"

value

="put"

/>

<

input

type

="button"

id="btnhead"

value

="head"

/>

<

input

type

="button"

id="btntrace"

value

="trace"

/>

<

input

type

="button"

id="btnoptions"

value

="options"

/>

div>

<

h3 id

="headertitle"

>response headers:

h3>

<

ul id

="headerresult"

class

="list-txt"

>

ul>

<

h3 id

="bodytitle"

>response body:

h3>

<

textarea

id="bodyresult"

class

="list-txt"

rows

="5"

disabled

="disabled"

>

textarea

>

controller中傳送trace請求: 

public

void

test()

else

response.end();

}public

void trace(string

url)

執行結果:

get/put/post的header及body類似,也很常見,這裡就不帖圖了

《http權威指南》閱讀筆記(三)

http報文組成 請求報文 頭部資訊 header 實體資訊 entity method 主要包括,head,put,delete,get,post,head 其中head,get,post常用 put,delete 不常用 head只是需要返回影響頭部 響應報文 http 版本號 狀態碼 描述 頭...

《HTTP權威指南》閱讀筆記

歷時兩個多月,終於把經典圖書 http權威指南 讀完了。雖然看上去厚厚的一本,實際上只要有一些計算機網路基礎,讀起來還是很順利的,並沒有想象中那麼難啃。全書講的很細緻,涵蓋了http的方方面面,其中有一些都是些眾所周知的常識,比如前幾張關於http的基本介紹 url與資源等,但是也值得讀一讀,能夠把...

《HTTP權威指南》閱讀筆記(六)

一 對http 進行解釋,將其與web閘道器進行對比,並說明如何部署 http的 伺服器 分為公共 和私人 是代表客戶端是代表客戶端完成事務的中間人,既是web伺服器又是web客戶端。http客戶端會向 傳送請求報文,伺服器必須向web伺服器一樣,正確的處理請求和連線,然後返回響應。同時,自身要向伺...