DelphiFAQ Home Search:

How can I read the HTTP response headers of the page?

 

comments4 comments. Current rating: 4 stars (2 votes). Leave comments and/ or rate it.

The browser object model doesn't provide access to these headers but in IE 5 and newer you have an ActiveX Object Microsoft.XMLDOM which can request the page and return the headers as shown below:

<script language="JavaScript" type="text/javascript">
<!--
var http = new ActiveXObject('Microsoft.XMLHTTP');

// display headers of current document:
http.open('HEAD', location.href, false);
http.send();
alert(http.getAllResponseHeaders())

// or display headers of yahoo.com:
http.open('HEAD', 'http://www.yahoo.com/', false);
http.send();
alert(http.getAllResponseHeaders())

//-->
</script>

Comments:

2006-08-16, 16:19:08
anonymous from United States  
rating
2008-04-18, 01:34:48
anonymous from India  
How to use this script? can you tell the complete procedure
2008-05-19, 15:51:12
anonymous from United States  
How to use it, depends on what you need it to do.
It fires off an AJAX request to the server to fetch just the headers for
the current page, so if you're on a page that has submitted some data or something
you'd get a duplicate request to the server.

If you just want to look at the headers for a given page really quickly int
the browser you can do it like this. (Adapted from above)
Copy the following string, and paste it into the location bar of your IE browser (doesn't
work in FF).
javascript:var http = new ActiveXObject('Microsoft.XMLHTTP');http.open('HEAD', location.href, false);http.send();alert(http.getAllResponseHeaders())

It'll fetch the headers for the page you're sitting on, and display them.
2008-06-20, 03:11:38
[hidden] from Yangon, Myanmar  
rating

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Los Angeles, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.