The code on the following works fine for simple url such as "www.google.com" but if the urlString has query
string such as "http://www.google.com/search?sourceid=navclient&q=velocity+apache", Exception throws on url.openStream(), I don't know why, because the url with query string is valid, but it just won't work. Could anyone help. Is there any alternative for this? I need it for url validation.
// open a connection to the url to get the size of the page
String urlString = "http://www.google.com/search?sourceid=navclient&q=velocity+apache"
URL url = null;
DataInputStream input = null;
try{
url = new URL(urlString);
InputStream in = url.openStream();
input = new DataInputStream(in);
} catch(Exception e) {
out.println("The url you provided can not be accessed, please try again");
return;
}
...