Hi everyone,
Consider this URL.
"http://forums.devx.com/newthread.php?do=newthread&f=104"
Some URLs have something that are called escape characters("?", etc")
Are these characters supposed to encoded using the URI class that has a method called toASCIIString() that returns the escaped characters as a US ASCII format
or simply by direct connection
or create a URI to URL conversion by using its toURL method
Which is actually the correct way of connecting to that URL??
This way
HttpURLConnection connection = null;
String p1 = "http://forums.devx.com/newthread.php?do=newthread&f=104";
URL url = new URL(p1);
connection = (HttpURLConnection)url.openConnection(); connection.connect();
//other codes to open the stream and read from it
Or this way
HttpURLConnection connection = null;
String p1 = "http://forums.devx.com/newthread.php?do=newthread&f=104";
URI uri = new URI(p1);
URL url = uri.toURL();
connection = (HttpURLConnection)url.openConnection(); connection.connect();
//other codes to open the stream and read from it
or this way
HttpURLConnection connection = null;
String p1 = "http://forums.devx.com/newthread.php?do=newthread&f=104";
URI uri = new URI(p1);
URL url = new URL(uri.totoASCIIString());
connection = (HttpURLConnection)url.openConnection(); connection.connect();
//other codes to open the stream and read from it
Are both correct or both wrong or only one is correct??
One more thing but isn't the purpose of the Java URI class supposed to encode any of the query statements in the URL and pass it back to the URL class using its toURL method. Correct me if i am wrong.
If i am wrong then what's the purpose of the Java URI class
I hope that someone could please clarify this
Thank You
Yours Sincerely
Richard West