相当于Python的Java的urllib.urlencode(基于HashMap的UrlEncode) [英] Java equivalent of Pythons urllib.urlencode(HashMap based UrlEncode)

查看:405
本文介绍了相当于Python的Java的urllib.urlencode(基于HashMap的UrlEncode)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自

Python的urllib.urlencode的Java等效语言是什么?
喜欢

Whats the java equivalent of Python’s urllib.urlencode?
Like

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

我可以在其中传递键值的HashMap并将其编码并提供给我url字符串..

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

我想避免这种情况

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");

使用

=

&

&

推荐答案

java.net.URLEncoder 应该可以为您工作-尽管您必须扩展它以接受哈希图-但这并不是很困难.

java.net.URLEncoder should work for you - though you would have to extend it to accept the hashmap - but that is not very difficult.

这篇关于相当于Python的Java的urllib.urlencode(基于HashMap的UrlEncode)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆