dotwin
dotwin

Reputation: 1332

URL Encoding Issue with "Œ"

I have read all of the Java URL encoding threads on here but still haven't found a solution to my problem: Google Chrome encodes "BŒUF" to "B%8CUF" POST data, awesome. How can I convince Java to do the same? (The website is <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr"> and <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> in case this is important.)

System.out.println(URLEncoder.encode("BŒUF", "utf-8"));
System.out.println(URLEncoder.encode("BŒUF", "iso-8859-1"));
System.out.println(URLEncoder.encode("BŒUF", "iso-8859-15"));
System.out.println(new URI("http","www.google.com","/ig/api","BŒUF", null).toASCIIString());

prints

B%C5%92UF
B%3FUF
B%BCUF
http://www.google.com/ig/api?B%C5%92UF

but not "B%8CUF"?

Upvotes: 0

Views: 855

Answers (1)

StoopidDonut
StoopidDonut

Reputation: 8617

You are specifically looking for windows-1252 encoding not UTF-8:

System.out.println(URLEncoder.encode("BŒUF", "windows-1252"));

Gives,

B%8CUF

Upvotes: 2

Related Questions