Search code examples
javaurlcharacter-encodingnon-english

Escape non english characters in a url


How can I escape non-english characters like "ö" from my url since it causes 404 response error. I am using Java. Please help me.


Solution

  • E.g. by using URL-Encoding as specified in RFC3986 (http://tools.ietf.org/html/rfc3986). Please also have a look at: http://en.wikipedia.org/wiki/Percent-encoding

    Java provides some methods to do this:

    http://download.oracle.com/javase/1.4.2/docs/api/java/net/URLEncoder.html

    Be aware of different encodings like ISO-8859-1/15, UTF-8. Depending on this for example an 'ö' will be encoded to %F6 or &C3%D6 (or sth. like this).