Thread: WebPage status
View Single Post
  #2 (permalink)  
Old August 6th, 2008, 06:13 PM
Old Pedant Old Pedant is offline
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

You are trying to make the call *asynchronously* (which means "don't wait for the answer") and so then you are trying to get the status before the answer is received. So of course you get the error.

Also, you test on the status is backwards. "200" means "ok".

So...

<script language="VBScript">

msgbox urlget("http://www.google.com")
Dim strPageStat

Function URLGet(URL)
  Set Http = CreateObject("Microsoft.XMLHTTP")
  Http.Open "GET", URL, False ' False means *synchronous*
  Http.Send ()
  strPageStat = Http.Status
  if strPageStat <> "200" then
      URLGet="Error:"& strPageStat
  else
      URLGet = Http.responseText
  end if
End Function
</script>

If you really want to do this asynch, you need to use the same kind of state change handler you would for Ajax.

Reply With Quote