[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

ASP Function to validate a URL

Posted on 2006-06-25
6
Medium Priority
?
1,177 Views
Last Modified: 2012-06-27
Hi,
I need an ASP funnction that can validate a URL from a form.
Could you pls direct me to one.
Thanx
0
Comment
Question by:dpinto04
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 21

Accepted Solution

by:
ap_sajith earned 200 total points
ID: 16978488
What do you mean validate?.. If you want to check the existance of a URL, then use the function below.

<%
Response.write CheckFileExists("http://www.mysite.com/index.asp")

'==============================================================
' Function to check if a specified URL exists specified URL
' Usage : Response.write CheckFileExists("http://www.mysite.com/index.asp")
'==============================================================
Function CheckFileExists(strURL)
      Dim oXMLHTTP ' As Object
      Dim strResult ' As String
      ' Create XMLHTTP Object
      '----------------------------
      Set oXMLHTTP = CreateObject("Microsoft.XMLHTTP")    
      ' Open connection using "POST" method, asynchronously
      '-----------------------------------------------------------------
      oXMLHTTP.Open "GET", strURL, False
      ' Send HTTP request to the server
      '--------------------------------------
      oXMLHTTP.Send
      ' Error Check
      '---------------
      If Err.Number = 0 Then
            ' Wait to receive response from server
            '---------------------------------------------
            strResult = oXMLHTTP.responseText
      End If
      ' Cleanup
      '----------
      Set oXMLHTTP = nothing
      ' Return the response to the caller
      '--------------------------------------
      If strResult<>"" Then
            CheckFileExists = True
      Else
            CheckFileExists = False
      End If
End Function
%>

Hope this helps...
Cheers!
0
 

Author Comment

by:dpinto04
ID: 16978514
By validate I mean check if its a URL that exists and does not some random stuff typed into the form

The above script gives me:
msxml3.dll (0x800C0005)
The system cannot locate the resource specified.
0
 
LVL 9

Expert Comment

by:david_levine
ID: 16978810
Here's an example - http://levinecentral.com/test/url_exists.asp

Here's the source:
<html>
<head><title>Check if URL exists</title></head>
<body>
<form method="POST" action="url_exists.asp">
      <p><input type="text" name="formURL" size="40" value="<%=request.form("formURL")%>"</p>
      <p><input type="submit" value="Check" name="B1"></p>
      <%
      if request.form("formURL") > "" then
            response.write("<hr><br>")
            Dim objXMLHTTP, strReturnStatus
            Set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
            objXMLHTTP.Open "GET", request.form("formURL"), False
            objXMLHTTP.Send
            strReturnStatus = objXMLHTTP.Status
            Set objXMLHTTP = Nothing
            
            if strReturnStatus = "200" then
                  response.write("URL " & request.form("formURL") & " was found.")
            else
                  response.write("URL " & request.form("formURL") & " was NOT found.")
            end if
      end if
      %>
</form>
</body>
</html>
0
 
LVL 9

Expert Comment

by:david_levine
ID: 16978839
Here's the same code with an "on error" to handle missing domains..

<html>
<head><title>Check if URL exists</title></head>
<body>
<form method="POST" action="url_exists.asp">
      <p><input type="text" name="formURL" size="40" value="<%=request.form("formURL")%>"</p>
      <p><input type="submit" value="Check" name="B1"></p>
      <%
      On Error Resume Next
      if request.form("formURL") > "" then
            response.write("<hr><br>")
            Dim objXMLHTTP, strReturnStatus
            Set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP")
            objXMLHTTP.Open "GET", request.form("formURL"), False
            objXMLHTTP.Send
            strReturnStatus = objXMLHTTP.Status
            Set objXMLHTTP = Nothing
            
            if strReturnStatus = "200" then
                  response.write("URL " & request.form("formURL") & " was found.")
            else
                  response.write("URL " & request.form("formURL") & " was NOT found.")
            end if
      end if
      %>
</form>
</body>
</html>
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question