How can I make URLEncoding not encode a colon?

I have a JSONObject:

{user:{"firstname":"testuser","surname":"æøå"}} 

So, I have these special characters in the object

I have URLEncode jsonString I have.

 urlEncodedJsonReq = URLEncoder.encode("{user:{\"firstname\":\"testuser\",\"surname\":\"æøå\"}}","UTF-8"); 

I get a response from the server: "Characters were not allowed in the URI you sent." This is a coded URL: serverurl/%7Buser%3A%7B%22firstname%22%3A%22testuser%22%2C%22surname%22%3A%22%C3%A6%C3%B8%C3%A5%22%7D%7D

But what I need:

 %7Buser:%7B%22firstname%22:%22testuser%22%2C%22surname%22:%22%C3%A6%C3%B8%C3%A5%22%7D%7D 

Is this possible in any reasonable way?

Thank you in advance

+4
source share
1 answer

Yes or just:

 URLEncoder.encode(theUrl).replace("%3A", ":"); 
+8
source

All Articles