Home:ALL Converter>get SENT headers in an XMLHttpRequest

get SENT headers in an XMLHttpRequest

Ask Time:2011-09-27T11:47:21         Author:Ahmad Nassri

Json Formatter

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?

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.

I'm using webkit/chrome, don't care about other browsers.

EDIT: 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.

Author:Ahmad Nassri,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/7564007/get-sent-headers-in-an-xmlhttprequest
Kenneth :

Try using Fiddler Web Debugger.\n\nhttp://www.fiddler2.com/fiddler2/\n\nYou can capture the request that was sent in any browser as well as inspect the request headers, response headers, and even copy a capture sent request and send it out as your own.",
2011-09-27T05:32:43
mix3d :

Assuming you are using jQuery, and you're looking for anything attached, but maybe not ALL headers sent, this could help. Not sure if it meets your exact needs, (since the browser tends to add its own things), but if you need to grab your own headers first, this works:\n\n$.ajaxSetup({\n beforeSend: function (jqXHR, settings) {\n if(!(settings.headers && settings.headers.token)) {\n //no token header was set, so set the request header\n jqXHR.setRequestHeader('token', newtoken);\n }\n }\n})\n",
2017-02-13T22:04:07
AmGates :

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.\n\nYou'll have to either have the server echo the headers, or use a packet sniffer like Wireshark.",
2011-09-27T05:00:13
yy