如何让URLEncoding不对冒号进行编码?
问题描述:
我有一个JSONObject:
I have a JSONObject:
{user:{"firstname":"testuser","surname":"æøå"}}
所以我在对象中有这些特殊字符
So i have these special characters in the object
I URLEncode我有的jsonString。
I URLEncode the jsonString i have.
urlEncodedJsonReq = URLEncoder.encode("{user:{\"firstname\":\"testuser\",\"surname\":\"æøå\"}}","UTF-8");
我收到服务器的回复:你提交的URI不允许使用字符。
这是编码的网址: serverurl /%7Buser%3A%7B%22firstname%22%3A%22testuser%22%2C%22sameame%22%3A%22%C3%A6%C3 %B8%C3%A5%22%7D%7D
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
但我需要的是:
%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?
提前致谢
答
是,或者干脆:
URLEncoder.encode(theUrl).replace("%3A", ":");