Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i make URLEncoding not encode colon?

Tags:

java

android

I have a JSONObject:

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

So i have these special characters in the object

I URLEncode the jsonString i have.

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

I get a response from the server: "The URI you submitted has disallowed characters.". This is the encoded 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 it to be:

%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?

Thanks in advance

like image 202
Ikky Avatar asked Oct 24 '11 11:10

Ikky


People also ask

How do you get the colon out of the URL?

If you want to include a colon as it is within a REST query URL, escape it by url encoding it into %3A .

Do colons need to be URL encoded?

Colon IS an invalid character in URL unless it is used for its purpose (for eg http://). "...Only alphanumerics [0-9a-zA-Z], the special characters "$-_. +! *'()," [not including the quotes - ed], and reserved characters used for their reserved purposes may be used unencoded within a URL."

Can a URL have colon?

It is completely fine to use a colon : in a URL path.


1 Answers

Yes, or simply:

URLEncoder.encode(theUrl).replace("%3A", ":");
like image 152
Maurice Perry Avatar answered Sep 29 '22 01:09

Maurice Perry