Wrox Programmer Forums
|
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 6th, 2008, 03:34 PM
Registered User
 
Join Date: Aug 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default WebPage status

I'm trying to verify a website is up or down by retrieving the status code using vbScript. I've seen the following example several times on the web, but get "unspecified error" for the line "strPageStat = Http.Status"

Below is the code. Any ideas on the error or another way to check if the website is functioning?

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

Function URLGet(URL)
  Set Http = CreateObject("Microsoft.XMLHTTP")
  Http.Open "GET", URL, True
  Http.Send ()
  strPageStat = Http.Status
  if strPageStat = "200" then
      URLGet="Error:"& strPageStat
      else
      ' URLGet = Http.ResponseBody
      URLGet = Http.responseText
  end if
  End Function


Reply With Quote
  #2 (permalink)  
Old August 6th, 2008, 06:13 PM
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
  #3 (permalink)  
Old August 7th, 2008, 08:57 AM
Registered User
 
Join Date: Aug 2008
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, that worked.

Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Webpage template help surendran Classic ASP Basics 2 June 8th, 2007 11:12 AM
print a webpage debjanib ASP.NET 2.0 Professional 1 January 1st, 2007 01:07 PM
e-mail a webpage rylemer Classic ASP Professional 5 July 11th, 2006 08:05 PM
To Load a webpage Nitu kumar RSS and Atom 0 April 3rd, 2006 04:39 AM
Printing webpage rajanikrishna HTML Code Clinic 1 February 2nd, 2005 09:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.