I send a query to a php file in order to receive a xml:
www.mydomain.com/order.php?item=€15,- shoes
For HTML I need the €-sign as: & e u r o ;
I tried:
try {
query=URLEncoder.encode(query,"UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
And the POST-url=www.mydomain.com/order.php?query
Problem with that is that the = sign also becomes encoded, and I get the error for the & e u r o ; (the ;-sign):
Caused by: java.lang.IllegalArgumentException: Illegal character in query at index
How do I encode this query?
You don't want to encode your whole query string.
Encode each parameter value before constructing the query string.
eg:
query = "item=" + URLEncoder.encode("€15")
Also, if you want &euro
that's not URL encoded but HTML escaped. Use URL encoding instead.