問(wèn)題描述
試圖從 XHR 對(duì)象中獲取請(qǐng)求標(biāo)頭,但沒(méi)有成功,是否存在該對(duì)象的隱藏方法或?qū)傩詴?huì)暴露瀏覽器發(fā)送的標(biāo)頭?
Trying to get the Request headers from the XHR object, but with no luck, is there a hidden method or property of that object that will expose the headers sent by the browser?
我已經(jīng)知道如何設(shè)置自定義請(qǐng)求標(biāo)頭和查看響應(yīng)標(biāo)頭,我正在尋找發(fā)送的所有請(qǐng)求標(biāo)頭的列表,瀏覽器創(chuàng)建的標(biāo)頭和我的自定義標(biāo)頭.
I already know how to set custom request headers and view the response headers, I'm looking to get a list of all REQUEST headers sent, ones created by the browser and my custom ones.
我用的是webkit/chrome,其他瀏覽器不用管.
I'm using webkit/chrome, don't care about other browsers.
我不想監(jiān)控請(qǐng)求,我正在構(gòu)建一個(gè)網(wǎng)絡(luò)應(yīng)用程序,我需要列出這些標(biāo)頭并在應(yīng)用程序中顯示它們,請(qǐng)不要告訴我有關(guān) fiddler、firebug 和 chrome 工具的信息,這不是我要找的.??p>
I'm not looking to monitor the request, I'm building a web app and I need to list those headers and display them within the app, please don't tell me about fiddler, firebug and chrome tools, that's not what I'm looking for.
推薦答案
XMLHttpRequest 中沒(méi)有方法API 獲取發(fā)送的請(qǐng)求標(biāo)頭.有一些方法可以僅獲取響應(yīng)標(biāo)頭,并設(shè)置請(qǐng)求標(biāo)頭.
There is no method in the XMLHttpRequest API to get the sent request headers. There are methods to get the response headers only, and set request headers.
您必須讓服務(wù)器回顯標(biāo)頭,或者使用像 Wireshark 這樣的數(shù)據(jù)包嗅探器.
You'll have to either have the server echo the headers, or use a packet sniffer like Wireshark.
這篇關(guān)于在 XMLHttpRequest 中獲取 SENT 標(biāo)頭的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!