|
it
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Does url exist?
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
http://www.aspfaq.com/2173
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 > > Show quote
"Henrik" <n*@email.dk> wrote in message Will this help? Watch for word-wrap.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 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 > With Server.CreateObject("Microsoft.XMLHTTP") FYI, this one isn't recommended for use from ASP... MSXML2.ServerXMLHTTP ismuch safer. 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....)
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 > > "Steven Burn" <somewhere@in-time.invalid> wrote in message Am I missing something here....... this doesn't return a value either way?.news:eqek$FkKFHA.3336@TK2MSFTNGP09.phx.gbl... 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") I think that he renamed another function when creating the example for you.
Change "Fetch" to "UrlExists" "Steven Burn" <somewhere@in-time.invalid> wrote in message Am I missing something here....... this doesn't return a value either way?. news:eqek$FkKFHA.3336@TK2MSFTNGP09.phx.gbl... 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....) 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 > > 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.....
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 > > > > > > Here you go.......
example: http://mysteryfcm.plus.com/misc/urlexists.asp Code: http://mysteryfcm.plus.com/misc/urlexists.asp.txt 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 > > Tis a modified version of one of the samples provided in Aaron's link btw.....
"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 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 > > 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 Tis a modified version of one of the samples provided in Aaron's linknews:eTrOAFkKFHA.3184@TK2MSFTNGP09.phx.gbl... btw..... "Steven Burn" <somewhere@in-time.invalid> wrote in message Here you go.......news:#RlntDkKFHA.3916@TK2MSFTNGP14.phx.gbl... example: http://mysteryfcm.plus.com/misc/urlexists.asp Code: http://mysteryfcm.plus.com/misc/urlexists.asp.txt 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 > > Duly changed.... ;o)
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 > > > > > > > |
|||||||||||||||||||||||