user2666218
user2666218

Reputation: 23

URL validation with UrlValidator class

I'm trying to validate a link, and with searching I've found about the UrlValidator class. However, it seems to be not working for me. I've chosen a random url to test.

String[] schemes = {"http", "https"};
UrlValidator urlValidator = new UrlValidator(schemes);
if(urlValidator.isValid("http://www.gonwaognwa.com/")){
    System.out.println("valid");
}else{
    System.out.println("invalid");
}

The following code prints valid when my browser can't even connect to it. Am I using it wrong?

My import line:

import org.apache.commons.validator.routines.UrlValidator;

Upvotes: 2

Views: 1544

Answers (1)

Ravi K Thapliyal
Ravi K Thapliyal

Reputation: 51721

UrlValidator is only checking for the syntactical correctness of the URL; not if you can actually connect to the web server or not. It only makes sure that a given URL conforms to Uniform Resource Identifiers (URI): Generic Syntax.

Upvotes: 2

Related Questions