I'm trying to build a URL using URIBuilder and for some reason I get + instead of %20 for space.
this is my code:
URI uri=null;
try {
uri = ub.setScheme("http")
.setHost("myalcoholist.com")
.setPath("/drink-management/view-drink-json")
.setParameter("flavor",(String)params[1])
.setParameter("brand",(String)params[2])
.setParameter("company",(String)params[3])
.build();
} catch (URISyntaxException e) {
Log.e("url", "could not parse url", e);
return null;
}
the parameters:
params[3] = {java.lang.String@831933398520}"contreau france."
params[2] = {java.lang.String@831933398384}"cointreau"
params[1] = {java.lang.String@831933398256}"orange"
the result URL:
"GET /drink-management/view-drink-json?flavor=orange&brand=cointreau&company=contreau+france. HTTP/1.1" 200 538 "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"
what do I need to change for the parameters to be properly encoded ?
thanks
I know this post is very old, but since it's the first result google gave me and had no answers, here is the way I resolved the problem:
Just use URLEncoder.encode(string, "UTF-8")
with the String (string being your own string) you want to make this change. This will encode all the characters in UTF-8 in your String to URL format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With