Pythons Java equivalent urllib.urlencode (HashMap based UrlEncode)

From

What is the java equivalent of Pythons urllib.urlencode?
how

>>> urllib.urlencode({'abc':'d f', 'def': '-!2'})
'abc=d+f&def=-%212'

Where can I pass the HashMap of the key values ​​and it encodes and gives me the url string.

Edit: I wanted to avoid this scenario

String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8");
    data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("value2", "UTF-8");

to manually concatenate strings with

=

and

&

+3
source share
1 answer

java.net.URLEncoder should work for you - although you will have to expand it to accept the hash map - but it is not very difficult.

+2
source

Source: https://habr.com/ru/post/1728958/


All Articles