Handling Live Web Content in WSH - Part 2 - Other Uses for XMLHttpRequest
(Page 6 of 6 )
Right about now you’re probably asking what else you can do with the XMLHttpRequest object. Well, here are a couple of other uses for you to play around with.
object.getResponseHeader(“header”)
The XMLHttpRequest object is also able to request a website’s headers. It provides two different methods for doing this. The getAllResponseHeaders() method will return all of the headers supplied by the server. The getResponseHeader() method can be used to request a specified header only. The following example demonstrates both.
Set objxmlHTTP = CreateObject("Msxml2.XMLHTTP")
objxmlHTTP.Open "HEAD", "http://www.aspfree.com", False
objxmlHTTP.Send()
Wscript.Echo “Return all headers:”
Wscript.Echo objxmlHTTP.getAllResponseHeaders()
Wscript.Echo “Return last modified date:”
Wscript.Echo objxmlHTTP.getResponseHeader("Last-Modified")
Set objxmlHTTP = Nothing
As you can see, we’ve used the getAllResponseHeaders() method to return all of the headers and the getResponseHeader method to return the Last-Modified headers. An example output might look like this:
Return all headers:
Date: Fri, 01 Dec 2006 20:00:05 GMT
Server: Apache/1.3.34 (Unix)
Set-Cookie: sessioncookie=c88b42fa00eb0b52045e8b3ce1621c5; expires=Sat, 01-Dec-2007 20:00:05 GMT; path=/
Set-Cookie: usercookie=c88b42fa00eb0b52045e8b3ce1621c5; expires=Sat, 02-Dec-2006 08:00:05 GMT; path=/
Set-Cookie: jamcku=nilpo; expires=Sat, 01-Dec-2007 20:00:05 GMT; path=/
Set-Cookie: jamckp=8ad7de41a5d1bda96b57ff2ca0e0b697; expires=Sat, 01-Dec-2007 20:00:05 GMT; path=/
Set-Cookie: mosvisitor=1
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Last-Modified: Fri, 01 Dec 2006 20:00:05 GMT
Cache-Control: no-store, no-cache, must-revalidate
Cache-Control: post-check=0, pre-check=0
Pragma: no-cache
Keep-Alive: timeout=10, max=150
Connection: Keep-Alive
Content-Type: text/html
Return last modified date:
Fri, 01 Dec 2006 20:00:05 GMT
Wipe the sweat off of your forehead and pour yourself a cold glass of tea. The hard work is done. You now have two more uses for the XMLHttpRequest object as well as some good methods for error-handling when using it. That’s it for now. I’ll catch you next time. Until then, keep on coding!

| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |