Uh oh. Looks like your using an ad blocker.
Our site is support by ads that help to pay our hosting costs. Please disable or whitelist us within your ad blocker to help us keep the site online.
All money generate by ads and donations is used to pay the hosting costs of the site.
View Thread
Author | Request header parsing | Member

Posts: Location:
Joined: 01.01.70 Rank: Guest | | Does anyone know a good way to get the request header details using javascript? I had a quick go with ajax and its xmlhttprequest class, but I couldnt get it to work for me. Its worth noting I want to read the request headers, not the response headers.
Id much prefer a simple javascript DOM affair, but other than document.cookie I cant seem to find one for the other request headers. The AJAX code im using now is:
Code
<script>
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("HEAD", "<url>",true);
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4) {
alert(xmlhttp.getAllResponseHeaders());
}
}
xmlhttp.send(null)
</script>
Am I on the right track with AJAX, or am I gonna need something else?
Edited by on 07-09-08 02:32 |
 |
Author | RE: Request header parsing | Member

Posts: Location:
Joined: 01.01.70 Rank: Guest | | Ok, i found this on a site, not sure but worth a try
Code
<script language="JavaScript"><!--
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var dateSent = null;
var dateComplete = null;
function RetrieveHTTPHeaders(url)
{
if (chkHEAD.checked)
xmlhttp.open("HEAD", "http:\/\/" + url, true); // Request just the header in an asynchronous call
else
xmlhttp.open("GET", "http:\/\/" + url, true); // Request all in an asynchronous call
xmlhttp.onreadystatechange = HandleState;
xmlhttp.setRequestHeader("pragma", "nocache");
dateSent = new Date();
xmlhttp.send("");
}
function HandleState()
{
var state = xmlhttp.readyState;
if (state == 1)
{
btnSubmit.disabled = true;
Status.innerText="";
Result.innerText="";
Body.innerText="";
ResponseTime.innerText="";
}
else if (state == 4)
{
dateComplete = new Date();
Status.innerText = xmlhttp.statusText + " (" + xmlhttp.status + ")";
Result.innerText = xmlhttp.getAllResponseHeaders();
Body.innerText = xmlhttp.responseText;
ResponseTime.innerText = ((dateComplete.valueOf() - dateSent.valueOf())/1000) + " seconds";
btnSubmit.disabled = false;
}
}
--></script>
And this is the site
http://www.whirlywiryweb.com/articles/getheaders.html
|
 |
Author | RE: Request header parsing | Member

Posts: Location:
Joined: 01.01.70 Rank: Guest | | Thanks for the reply, but im trying to actually understand this, not be a skid. Also,from my (very) limited knowledge of AJAX, that code doesnt do quite what I want, but it has some of the bits I was coding in it.
|
 |
Author | RE: Request header parsing | Member

Posts: Location:
Joined: 01.01.70 Rank: Guest | | Ok, does anyone know if it is at least possible to read request headers with JS?
|
 |
|