Recently, I had a situation where I had to pull down a HTML page to compare it to a known copy of the page. Certainly, IE or FireFox– or Google’s Chrome would have done the trick and I could have viewed the source. But that would require me to do work every time we needed to check the page against the known good source.
Instead I wrote a script to pull the HTML source and echo the response to the console (or a messag box if you are not using cscript to execute the script). While not a full blown HTTP QA script it does do the job of getting the HTTP responses from the server and is certainly a core part of any QA script anyone would write.
Basically the script uses the Microsoft.XMLHTTP object to preform all the HTTP calls and retrieve the HTML page. It sounds scary, but if you look at the script below I think you’ll find that it really is quite easy to accomplish. So, here is the script’s code:
Set WshShell = WScript.CreateObject(“WScript.Shell”)
Set http = CreateObject(“Microsoft.XmlHttp”)
On Error Resume Next
http.open “GET”, URL, False
if err.Number = 0 Then
Wscript.Echo “error ” & Err.Number & “: ” & Err.Description
set WshShell = Nothing
Set http = Nothing