Python的Java等价物urllib.urlencode(基于HashMap的urlencode)
Python的urllib.urlencode的java等价物是什么?Python的Java等价物urllib.urlencode(基于HashMap的urlencode),java,python,url,encoding,urlencode,Java,Python,Url,Encoding,Urlencode,Python的urllib.urlencode的java等价物是什么? 像 在这里,我可以传递键值的HashMap,它进行编码并提供url字符串 编辑:我想避免这种情况 String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8"); data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEn
像 在这里,我可以传递键值的HashMap,它进行编码并提供url字符串 编辑:我想避免这种情况
String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8");
data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("value2", "UTF-8");
手动将字符串与
=
及
&
应该对您有用-尽管您必须扩展它以接受hashmap-但这并不困难 是-可以通过使用hashmap和循环来避免这种情况:)
String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8");
data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("value2", "UTF-8");