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

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -