What did people do before URLEncode.encode (String s, String enc) arrived in JDK1.4??

S

Soefara

I'm trying to write some Java code to simulate a HTTP request
(either a GET or a POST) and have discovered that Java's
URLEncoder.encode(String s) does not treat double-byte
character sets properly in JDK1.3

I notice that JDK1.4 does contain a new URLEncoder.encode(String s, String enc)
method that takes an encoding parameter but I'm forced to use
JDK1.3 for backwards compatibility reasons.

What did people do back then (in JDK1.3 days) to
URLencode requests which could be a mix of alphanumeric and
double-byte characters ?

Am I the only person still using JDK1.3 and not JDK1.4 or JDK1.5 ?

Soefara.
 
C

Claire

I'm trying to write some Java code to simulate a HTTP request
(either a GET or a POST) and have discovered that Java's
URLEncoder.encode(String s) does not treat double-byte
character sets properly in JDK1.3

I notice that JDK1.4 does contain a new URLEncoder.encode(String s, String enc)
method that takes an encoding parameter but I'm forced to use
JDK1.3 for backwards compatibility reasons.

What did people do back then (in JDK1.3 days) to
URLencode requests which could be a mix of alphanumeric and
double-byte characters ?

Am I the only person still using JDK1.3 and not JDK1.4 or JDK1.5 ?

Soefara.

Hallo Soefara,
have you tried URLDecoder.decode(String s)?

Claire
 
S

Soefara

Hi Claire,

I'm actually trying to "URL encode" some parameters
as opposed to "decode" a querystring.

I have since found the following urlEncode method which
apparently works for double-byte characters, though why
and how it works I don't fully understand ~

public static String urlEncode(String s) {
char ch;
StringBuffer str=new StringBuffer();
for (int i=0;i<s.length();i++) {
ch=s.charAt(i);
if (ch>0x80) {
str.append("%"+Integer.toHexString((int)ch).toUpperCase());
ch=s.charAt(++i);
str.append("%"+Integer.toHexString((int)ch).toUpperCase());
}
else {
str.append(URLEncoder.encode(""+ch));
}
}
return str.toString();
}

Thanks for trying to help,

Soefara
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,187
Members
46,730
Latest member
AudryNolan

Latest Threads

Top