Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get SENT headers in an XMLHttpRequest

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.

like image 696
Ahmad Nassri Avatar asked Sep 27 '11 03:09

Ahmad Nassri


People also ask

How do I get headers in XMLHttpRequest?

setRequestHeader() The XMLHttpRequest method setRequestHeader() sets the value of an HTTP request header. When using setRequestHeader() , you must call it after calling open() , but before calling send() . If this method is called several times with the same header, the values are merged into one single request header.

Where do I find response headers?

To check this Location in action go to Inspect Element -> Network check the response header for Location like below, Location is highlighted you can see.


2 Answers

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.

You'll have to either have the server echo the headers, or use a packet sniffer like Wireshark.

like image 91
AmGates Avatar answered Oct 13 '22 10:10

AmGates


Try using Fiddler Web Debugger.

http://www.fiddler2.com/fiddler2/

You 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.

like image 38
Kenneth Avatar answered Oct 13 '22 10:10

Kenneth