Skip to content Skip to sidebar Skip to footer

Encoding Url With German Characters

In my app I receive a URL such as http://www.wassersportlotse.de/php/lib/smart_image_resizer/image.php/Mühlendammschleuse.jpg?image=/media/images/uploads/Mühlendammschleuse.jpg

Solution 1:

Maybe the encoder das encode the Umlaut as UTF-8 characters (so ü would be encoded with two characters) and they are not put back together properly at the server (for us it didn't work with Tomcat). To solve this situation we used URLEncoder.encode(param, "ISO-8859-1") to encode the parameters.

Solution 2:

There's no simple answer, because it depends on the server serving that URI which encoding is expected.

Usually it's UTF-8.

In that case: use String.getBytes, specifying the UTF-8 encoding, and obtain a byte array from that. Re-encode that byte array as string by taking all bytes <= 127 as-is, and substituting all others by the %hh form. (percent sign, then two hex digits). See http://greenbytes.de/tech/webdav/rfc3986.html#rfc.section.2.1.

Solution 3:

You can use Android's Uri class to help you out. That class has an encode() method which will use UTF-8 to encode your string.

Solution 4:

I recently had a problem with URLs for images whose names included umlauts and German special characters, and I lost a day looking for the solution. The images simply did not appear if there was an ä or and ü in the file name or the directory name. I thought it might be spring, or some other Java technology I am working with, or in the browser. And strangely enough, even with the url encoded, it failed to find the image. But in the end, the solution was in my tomcat server.xml configuration. In your server.xml file, find your connector and add these two lines:

URIEncoding="UTF-8"useBodyEncodingForURI="true"

At the end, it should look something like this:

<Connector connectionTimeout="20000"
port="8080" 
protocol="HTTP/1.1" 
redirectPort="8443"
URIEncoding="UTF-8"
useBodyEncodingForURI="true"/>

Now I do not need to url-encode the url. This is a help to my clients, because they can see the German words in the urls spelled correctly.

Here is another tip: if you are coding in eclipse and starting and stopping your server from inside eclipse, then the configuration file (server.xml) could be in your eclipse workspace in the Servers folder. It must be changed here for it to work with eclipse. This can be maddening, when you have made the change in your principal tomcat configuration, and the urls work there, but they are still broken when running the server in eclipse.

That did it for me. I hope it helps someone out there! :-)

Solution 5:

Have your tried unsing:

android.net.Uri.encode(urlString, ":/");

It encodes the string but skips ":" and "/".

Post a Comment for "Encoding Url With German Characters"