Script recipe: how to query a HTTP/HTTPS web page

It is sometimes hard to diagnose browser problems. For example if you have problems loading a certain page, you don't know whether this is a browser problem or an web server problem. Maybe you have the wrong browser settings (for example bad certificates for a HTTPS site). Or probably the web server does not respond normally to HTTP requests?

A simple way to diagnose such problems is to get the page through a different method, without involving the browser. You can use XMLHTTP - the thing that everyone talks about these days. Take for example the following simple script:

dim sxh
set sxh = CreateObject("MSXML2.XMLHTTP.3.0")
sxh.open "GET",wscript.arguments(0),false
sxh.send

Dim page
page = sxh.responsetext
wscript.echo page

If you launch this script with an URL in its parameter, you will get back the page at that URL. It's that simple!

cscript //NoLogo get1.vbs https://search.msn.com > test1.htm

This technique is also very useful if you want to "poke around" and to see the contents of a web page, without giving the browser a chance to react on it. For example, when the page contains a "redirect" script or instruction, there is no better way to get the contents of the HTML page.