to encode or not to encode
Suppose you have a link:
String location =
"http://www.website.com/my spaced dir/ccnt.html";
According to the URL specification some of these characters need encoding.
Does that mean the URL should be created like so:
URI uri = new URI(location);
String str = uri.toASCIIString();
URL url = new URL(str);
Is that the way to encode such a link before creating its URLConnection?
[432 byte] By [
NovaLokaa] at [2007-11-27 11:41:27]

# 1
Nope. use:
static String java.net.URLEncoder.encode(String url, String scheme);
Regarding to w3c standards, you should use "UTF-8" as the encoding scheme.
# 2
Class URLEncoder
Utility class for HTML form encoding.
Form encoding is different from URI encoding, as I see it..
Eg.
A space URI-encoded reads %20
A space HTML-form encoded reads +
# 3
> Form encoding is different from URI encoding, as I
> see it..
Please post a reference to the two specification that you are using?
# 4
My question remains unanswered:
should I encode (and how!) or not encode before fetching a URLConnection
Using encoding by escaped octets to ASCII:
java.net
Class URI
RFC 2396 allows escaped octets to appear in the user-info, path, query, and fragment components. Escaping serves two purposes in URIs:
* To encode non-US-ASCII characters when a URI is required to conform strictly to RFC 2396 by not containing any "other" characters.
"other": The Unicode characters that are not in the US-ASCII character set, are not control characters (according to the Character.isISOControl method), and are not space characters (according to the Character.isSpaceChar method) (Deviation from RFC 2396, which is limited to US-ASCII)
This is NOT the HTML-form encoding:
application/x-www-form-urlencoded MIME format
# 5
Yes, I felt I had to create my own encoding method for URI and URL.
If I could have pasted nice and clean <pre> code here,
I would have pasted it.
Message was edited by:
NovaLoka