File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Sockets and Internet Protocols and the fly likes URL connection problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "URL connection problem" Watch "URL connection problem" New topic

URL connection problem

Ming Chen

Joined: Mar 14, 2002
Posts: 13
The code on the following works fine for simple url such as "" but if the urlString has query string such as "", 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 = ""
URL url = null;
DataInputStream input = null;
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");
Sunil Palicha

Joined: Jul 24, 2002
Posts: 11
The probable problem is the '&' in the url that u r specifying.
U got to encode the URL.
static String encode(String s, String enc)
Translates a string into application/x-www-form-urlencoded format using a specific encoding scheme.
I agree. Here's the link:
subject: URL connection problem
It's not a secret anymore!