url - how can I use encoding URIbuilder() method in Java -


i'm using api in java.

i need use korean text in uri, , request string variable.
if set request = "안녕하세요"; , use code:

final uri uri = new uribuilder().setscheme("https").sethost(server + "api.net").setpath("/api/" + "/" + **request**).setparameters(param).build(). ; 

if use this, can see following result:

https://api.net/api/%ec%95%88%eb%85%95%ed%95%98%ec%84%b8%ec%9a%94?api_key

i tried use code:

final uri uri = new uribuilder().setscheme("https").sethost(server + "api.net").setpath("/api/" + "/" + **urlencoder.encode(request, "utf-8")**).setparameters(param).build(). ; 

but getting same result.

how can solve problem?

your uri has been encoded. url, can't use special characters, if want retrieve request string, must decode specific part of uri, this:

string result = java.net.urldecoder.decode(uri.getpath(), "utf-8"); system.out.println(result);          // print "/api/안녕하세요" 

the rfc 3986, uniform resource identifier (uri): generic syntax confirms it:

a uri sequence of characters limited set: letters of basic latin alphabet, digits, , few special characters.

later says:

percent-encoded octets [...] may used within uri represent characters outside range of us-ascii coded character set if representation allowed scheme or protocol element in uri referenced.

which bunch of characters getting.

hope find useful.


Comments

Popular posts from this blog

Process 'command 'F:\android-sdk\build-tools\21.1.2\aapt.exe'' finished with non-zero exit value 1 -

apache - setting document root in antoher partition on ubuntu -

java - Updating to mongo 3.0 -