Home All Groups Group Topic Archive Search About


Author
16 Mar 2005 3:18 PM
Henrik
Hi

How do I find out if an url exists? Whar I want is a function like this:

If UrlExists("http://www.test.com/test.html") Then
    Response.Write("Yeah!!")
Else
    Response.Write("No file :-(")
End If

Can anyone help?

/Henrik

Author
16 Mar 2005 3:19 PM
Aaron [SQL Server MVP]
http://www.aspfaq.com/2173

--
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.




Show quote
"Henrik" <n*@email.dk> wrote in message
news:42384e50$0$24082$4d4eb98e@news.dk.uu.net...
> Hi
>
> How do I find out if an url exists? Whar I want is a function like this:
>
> If UrlExists("http://www.test.com/test.html") Then
>     Response.Write("Yeah!!")
> Else
>     Response.Write("No file :-(")
> End If
>
> Can anyone help?
>
> /Henrik
>
>
Author
16 Mar 2005 3:32 PM
McKirahan
Show quote
"Henrik" <n*@email.dk> wrote in message
news:42384e50$0$24082$4d4eb98e@news.dk.uu.net...
> Hi
>
> How do I find out if an url exists? Whar I want is a function like this:
>
> If UrlExists("http://www.test.com/test.html") Then
>     Response.Write("Yeah!!")
> Else
>     Response.Write("No file :-(")
> End If
>
> Can anyone help?
>
> /Henrik


Will this help?  Watch for word-wrap.

Function UrlExists(URL)
    On Error Resume Next
    Err.Clear
    Dim b
    With Server.CreateObject("Microsoft.XMLHTTP")
        .Open "GET",URL,False
        .Send
    b = .ResponseBody
        If Err.Number <> 0 Or .Status <> 200 Then
            Fetch = False
            Exit Function
        End If
    End With
    Fetch = Err.Number = 0
End Function


I think that the object may vary by Windows version:

    CreateObject("Microsoft.XMLHTTP")
    CreateObject("MSXML2.ServerXMLHTTP")
    CreateObject("MSXML2.ServerXMLHTTP.3.0")


So perhaps the following will work (untested):

Function UrlExists(URL)
    On Error Resume Next
    Err.Clear
    Dim booXML
        booXML= False
    Dim strXML
    Dim objXML
    Set objXML = Server.CreateObject("Microsoft.XMLHTTP")
    If Err.Number = 0 Then
        booXML = True
    Else
        Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
        If Err.Number = 0 Then
            booXML = True
        Else
            Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
            If Err.Number = 0 Then
                booXML = True
            End If
        End If
        Err.Clear
    End If
        objXML.Open "GET",URL,False
        objXML.Send
        strXML = .ResponseText
    If Err.Number <> 0 Or objXML.Status <> 200 Then
        Fetch = False
        Exit Function
    End If
    Fetch = Err.Number = 0
End Function
Author
16 Mar 2005 3:37 PM
Aaron [SQL Server MVP]
>     With Server.CreateObject("Microsoft.XMLHTTP")

FYI, this one isn't recommended for use from ASP... MSXML2.ServerXMLHTTP is
much safer.
Author
16 Mar 2005 4:01 PM
Steven Burn
Am I missing something here....... this doesn't return a value either way?. Where is the code telling the function to pass Fetch to URLExists? (tried adding that part myself btw and it still didn't return a value....)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Show quote
"McKirahan" <N***@McKirahan.com> wrote in message news:cZydnRrZQ6LuzKXfRVn-rg@comcast.com...
> "Henrik" <n*@email.dk> wrote in message
> news:42384e50$0$24082$4d4eb98e@news.dk.uu.net...
> > Hi
> >
> > How do I find out if an url exists? Whar I want is a function like this:
> >
> > If UrlExists("http://www.test.com/test.html") Then
> >     Response.Write("Yeah!!")
> > Else
> >     Response.Write("No file :-(")
> > End If
> >
> > Can anyone help?
> >
> > /Henrik
>
>
> Will this help?  Watch for word-wrap.
>
> Function UrlExists(URL)
>     On Error Resume Next
>     Err.Clear
>     Dim b
>     With Server.CreateObject("Microsoft.XMLHTTP")
>         .Open "GET",URL,False
>         .Send
>     b = .ResponseBody
>         If Err.Number <> 0 Or .Status <> 200 Then
>             Fetch = False
>             Exit Function
>         End If
>     End With
>     Fetch = Err.Number = 0
> End Function
>
>
> I think that the object may vary by Windows version:
>
>     CreateObject("Microsoft.XMLHTTP")
>     CreateObject("MSXML2.ServerXMLHTTP")
>     CreateObject("MSXML2.ServerXMLHTTP.3.0")
>
>
> So perhaps the following will work (untested):
>
> Function UrlExists(URL)
>     On Error Resume Next
>     Err.Clear
>     Dim booXML
>         booXML= False
>     Dim strXML
>     Dim objXML
>     Set objXML = Server.CreateObject("Microsoft.XMLHTTP")
>     If Err.Number = 0 Then
>         booXML = True
>     Else
>         Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
>         If Err.Number = 0 Then
>             booXML = True
>         Else
>             Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
>             If Err.Number = 0 Then
>                 booXML = True
>             End If
>         End If
>         Err.Clear
>     End If
>         objXML.Open "GET",URL,False
>         objXML.Send
>         strXML = .ResponseText
>     If Err.Number <> 0 Or objXML.Status <> 200 Then
>         Fetch = False
>         Exit Function
>     End If
>     Fetch = Err.Number = 0
> End Function
>
>
Author
17 Mar 2005 11:18 AM
McKirahan
"Steven Burn" <somewhere@in-time.invalid> wrote in message
news:eqek$FkKFHA.3336@TK2MSFTNGP09.phx.gbl...
Am I missing something here....... this doesn't return a value either way?.
Where is the code telling the function to pass Fetch to URLExists? (tried
adding that part myself btw and it still didn't return a value....)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

[snip]

Yeah, me bad.

I renamed the function without renaming  it within itself.

Try this:

If UrlExists("http://www.test.com/test.html") Then
   Response.Write("Yeah!!")
Else
   Response.Write("No file :-(")
End If

Function UrlExists(xURL)
    On Error Resume Next
    Err.Clear
    With CreateObject("MSXML2.ServerXMLHTTP")
        .Open "HEAD",xURL,False
        .Send
        If Err.Number <> 0 Or .Status <> 200 Then
            UrlExists = False
            Exit Function
        End If
    End With
    UrlExists = Err.Number = 0
End Function

Thanks to:
    Aaron (re "MSXML2.ServerXMLHTTP")
    Jonathan (re "HEAD")
Author
17 Mar 2005 4:02 PM
Mark Schupp
I think that he renamed another function when creating the example for you.
Change "Fetch" to "UrlExists"

--
--Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com

"Steven Burn" <somewhere@in-time.invalid> wrote in message
news:eqek$FkKFHA.3336@TK2MSFTNGP09.phx.gbl...
Am I missing something here....... this doesn't return a value either way?.
Where is the code telling the function to pass Fetch to URLExists? (tried
adding that part myself btw and it still didn't return a value....)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Show quote
"McKirahan" <N***@McKirahan.com> wrote in message
news:cZydnRrZQ6LuzKXfRVn-rg@comcast.com...
> "Henrik" <n*@email.dk> wrote in message
> news:42384e50$0$24082$4d4eb98e@news.dk.uu.net...
> > Hi
> >
> > How do I find out if an url exists? Whar I want is a function like this:
> >
> > If UrlExists("http://www.test.com/test.html") Then
> >     Response.Write("Yeah!!")
> > Else
> >     Response.Write("No file :-(")
> > End If
> >
> > Can anyone help?
> >
> > /Henrik
>
>
> Will this help?  Watch for word-wrap.
>
> Function UrlExists(URL)
>     On Error Resume Next
>     Err.Clear
>     Dim b
>     With Server.CreateObject("Microsoft.XMLHTTP")
>         .Open "GET",URL,False
>         .Send
>     b = .ResponseBody
>         If Err.Number <> 0 Or .Status <> 200 Then
>             Fetch = False
>             Exit Function
>         End If
>     End With
>     Fetch = Err.Number = 0
> End Function
>
>
> I think that the object may vary by Windows version:
>
>     CreateObject("Microsoft.XMLHTTP")
>     CreateObject("MSXML2.ServerXMLHTTP")
>     CreateObject("MSXML2.ServerXMLHTTP.3.0")
>
>
> So perhaps the following will work (untested):
>
> Function UrlExists(URL)
>     On Error Resume Next
>     Err.Clear
>     Dim booXML
>         booXML= False
>     Dim strXML
>     Dim objXML
>     Set objXML = Server.CreateObject("Microsoft.XMLHTTP")
>     If Err.Number = 0 Then
>         booXML = True
>     Else
>         Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
>         If Err.Number = 0 Then
>             booXML = True
>         Else
>             Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
>             If Err.Number = 0 Then
>                 booXML = True
>             End If
>         End If
>         Err.Clear
>     End If
>         objXML.Open "GET",URL,False
>         objXML.Send
>         strXML = .ResponseText
>     If Err.Number <> 0 Or objXML.Status <> 200 Then
>         Fetch = False
>         Exit Function
>     End If
>     Fetch = Err.Number = 0
> End Function
>
>
Author
17 Mar 2005 4:50 PM
Steven Burn
I tried that before mentioning it and it still wouldn't work on this PC (as I mentioned, it didn't return a value either way, nor did it return an error)..... I basically had to strip out all of the If's/Then's for the different XMLHTTP versions and just leave MSXML2.ServerXMLHTTP for it to work.....

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Show quote
"Mark Schupp" <notva***@email.net> wrote in message news:ePlO#vwKFHA.3788@tk2msftngp13.phx.gbl...
> I think that he renamed another function when creating the example for you.
> Change "Fetch" to "UrlExists"
>
> --
> --Mark Schupp
> Head of Development
> Integrity eLearning
> www.ielearning.com
>
> "Steven Burn" <somewhere@in-time.invalid> wrote in message
> news:eqek$FkKFHA.3336@TK2MSFTNGP09.phx.gbl...
> Am I missing something here....... this doesn't return a value either way?.
> Where is the code telling the function to pass Fetch to URLExists? (tried
> adding that part myself btw and it still didn't return a value....)
>
> --
> Regards
>
> Steven Burn
> Ur I.T. Mate Group
> www.it-mate.co.uk
>
> Keeping it FREE!
>
> "McKirahan" <N***@McKirahan.com> wrote in message
> news:cZydnRrZQ6LuzKXfRVn-rg@comcast.com...
> > "Henrik" <n*@email.dk> wrote in message
> > news:42384e50$0$24082$4d4eb98e@news.dk.uu.net...
> > > Hi
> > >
> > > How do I find out if an url exists? Whar I want is a function like this:
> > >
> > > If UrlExists("http://www.test.com/test.html") Then
> > >     Response.Write("Yeah!!")
> > > Else
> > >     Response.Write("No file :-(")
> > > End If
> > >
> > > Can anyone help?
> > >
> > > /Henrik
> >
> >
> > Will this help?  Watch for word-wrap.
> >
> > Function UrlExists(URL)
> >     On Error Resume Next
> >     Err.Clear
> >     Dim b
> >     With Server.CreateObject("Microsoft.XMLHTTP")
> >         .Open "GET",URL,False
> >         .Send
> >     b = .ResponseBody
> >         If Err.Number <> 0 Or .Status <> 200 Then
> >             Fetch = False
> >             Exit Function
> >         End If
> >     End With
> >     Fetch = Err.Number = 0
> > End Function
> >
> >
> > I think that the object may vary by Windows version:
> >
> >     CreateObject("Microsoft.XMLHTTP")
> >     CreateObject("MSXML2.ServerXMLHTTP")
> >     CreateObject("MSXML2.ServerXMLHTTP.3.0")
> >
> >
> > So perhaps the following will work (untested):
> >
> > Function UrlExists(URL)
> >     On Error Resume Next
> >     Err.Clear
> >     Dim booXML
> >         booXML= False
> >     Dim strXML
> >     Dim objXML
> >     Set objXML = Server.CreateObject("Microsoft.XMLHTTP")
> >     If Err.Number = 0 Then
> >         booXML = True
> >     Else
> >         Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
> >         If Err.Number = 0 Then
> >             booXML = True
> >         Else
> >             Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
> >             If Err.Number = 0 Then
> >                 booXML = True
> >             End If
> >         End If
> >         Err.Clear
> >     End If
> >         objXML.Open "GET",URL,False
> >         objXML.Send
> >         strXML = .ResponseText
> >     If Err.Number <> 0 Or objXML.Status <> 200 Then
> >         Fetch = False
> >         Exit Function
> >     End If
> >     Fetch = Err.Number = 0
> > End Function
> >
> >
>
>
Author
16 Mar 2005 3:57 PM
Steven Burn
Here you go.......

example:

http://mysteryfcm.plus.com/misc/urlexists.asp

Code:

http://mysteryfcm.plus.com/misc/urlexists.asp.txt

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Show quote
"Henrik" <n*@email.dk> wrote in message news:42384e50$0$24082$4d4eb98e@news.dk.uu.net...
> Hi
>
> How do I find out if an url exists? Whar I want is a function like this:
>
> If UrlExists("http://www.test.com/test.html") Then
>     Response.Write("Yeah!!")
> Else
>     Response.Write("No file :-(")
> End If
>
> Can anyone help?
>
> /Henrik
>
>
Author
16 Mar 2005 3:59 PM
Steven Burn
Tis a modified version of one of the samples provided in Aaron's link btw.....

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Steven Burn" <somewhere@in-time.invalid> wrote in message news:#RlntDkKFHA.3916@TK2MSFTNGP14.phx.gbl...
Here you go.......

example:

http://mysteryfcm.plus.com/misc/urlexists.asp

Code:

http://mysteryfcm.plus.com/misc/urlexists.asp.txt

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Show quote
"Henrik" <n*@email.dk> wrote in message news:42384e50$0$24082$4d4eb98e@news.dk.uu.net...
> Hi
>
> How do I find out if an url exists? Whar I want is a function like this:
>
> If UrlExists("http://www.test.com/test.html") Then
>     Response.Write("Yeah!!")
> Else
>     Response.Write("No file :-(")
> End If
>
> Can anyone help?
>
> /Henrik
>
>
Author
17 Mar 2005 4:36 AM
Jonathan Dodds
In the xmlhttp.open call consider changing the HTTP method from GET to HEAD.

The HEAD method will return only the headers, not the whole document. i.e.
HEAD is faster than GET. Since the point is only to check for the existence
of some resource at the specified URL, HEAD is sufficient.

(What's the HEAD method for? Browsers and proxy servers can use the HEAD
method to check if a cached page has been updated.)


"Steven Burn" <somewhere@in-time.invalid> wrote in message
news:eTrOAFkKFHA.3184@TK2MSFTNGP09.phx.gbl...
Tis a modified version of one of the samples provided in Aaron's link
btw.....

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"Steven Burn" <somewhere@in-time.invalid> wrote in message
news:#RlntDkKFHA.3916@TK2MSFTNGP14.phx.gbl...
Here you go.......

example:

http://mysteryfcm.plus.com/misc/urlexists.asp

Code:

http://mysteryfcm.plus.com/misc/urlexists.asp.txt

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Show quote
"Henrik" <n*@email.dk> wrote in message
news:42384e50$0$24082$4d4eb98e@news.dk.uu.net...
> Hi
>
> How do I find out if an url exists? Whar I want is a function like this:
>
> If UrlExists("http://www.test.com/test.html") Then
>     Response.Write("Yeah!!")
> Else
>     Response.Write("No file :-(")
> End If
>
> Can anyone help?
>
> /Henrik
>
>
Author
17 Mar 2005 10:32 AM
Steven Burn
Duly changed.... ;o)

--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Show quote
"Jonathan Dodds" <NO_REPLY> wrote in message news:ufEMiqqKFHA.4028@tk2msftngp13.phx.gbl...
> In the xmlhttp.open call consider changing the HTTP method from GET to HEAD.
>
> The HEAD method will return only the headers, not the whole document. i.e.
> HEAD is faster than GET. Since the point is only to check for the existence
> of some resource at the specified URL, HEAD is sufficient.
>
> (What's the HEAD method for? Browsers and proxy servers can use the HEAD
> method to check if a cached page has been updated.)
>
>
> "Steven Burn" <somewhere@in-time.invalid> wrote in message
> news:eTrOAFkKFHA.3184@TK2MSFTNGP09.phx.gbl...
> Tis a modified version of one of the samples provided in Aaron's link
> btw.....
>
> --
> Regards
>
> Steven Burn
> Ur I.T. Mate Group
> www.it-mate.co.uk
>
> Keeping it FREE!
>
> "Steven Burn" <somewhere@in-time.invalid> wrote in message
> news:#RlntDkKFHA.3916@TK2MSFTNGP14.phx.gbl...
> Here you go.......
>
> example:
>
> http://mysteryfcm.plus.com/misc/urlexists.asp
>
> Code:
>
> http://mysteryfcm.plus.com/misc/urlexists.asp.txt
>
> --
> Regards
>
> Steven Burn
> Ur I.T. Mate Group
> www.it-mate.co.uk
>
> Keeping it FREE!
>
> "Henrik" <n*@email.dk> wrote in message
> news:42384e50$0$24082$4d4eb98e@news.dk.uu.net...
> > Hi
> >
> > How do I find out if an url exists? Whar I want is a function like this:
> >
> > If UrlExists("http://www.test.com/test.html") Then
> >     Response.Write("Yeah!!")
> > Else
> >     Response.Write("No file :-(")
> > End If
> >
> > Can anyone help?
> >
> > /Henrik
> >
> >
>
>
>

AddThis Social Bookmark Button