java - The right encoding for `URLEncoder.encode` -
i trying standardize messages in urls , using urlencoder.encode
. problem that, output not seem valid url. example
val text = some("test question (a) x (b) y").get val query = "http://localhost:8080/ask?text=" + text println(query) val queryenc = urlencoder.encode(query, "utf-8") println(queryenc)
wich outputs:
http://localhost:8080/ask?text=test question (a) x (b) y http%3a%2f%2flocalhost%3a8080%2fask%3ftext%3dtest+question+%28a%29+x+%28b%29+y
is output valid url? (it doesn't valid, chrome , safari on machine don't recognize it).
you must encode each parameter value. not whole url.
val query = "http://localhost:8080/ask?text=" + urlencoder.encode(text, "utf-8")
Comments
Post a Comment