Clojure构建URL的组成部分

Python中,我将执行以下操作:

>>> q = urllib.urlencode({"q": "clojure url"})
>>> q
'q=clojure+url'

>>> url = "https://stackoverflow.com/search?" + q
>>> url
'https://stackoverflow.com/search?q=clojure+url'

如何在Clojure中执行上述所有编码?换句话说,我该怎么做类似于以下的事情呢?

=> (build-url "https://stackoverflow.com/search" {"q" "clojure url"})
"https://stackoverflow.com/search?q=clojure+url"
这是一种方法:

user=> (import [java.net URLEncoder])                                                      
java.net.URLEncoder
user=> (str "https://stackoverflow.com/search?q=" (URLEncoder/encode "clojure url" "UTF-8"))
"https://stackoverflow.com/search?q=clojure+url"

我知道这与Python代码片段不尽相同.请参阅Clojure邮件列表中的以下帖子以获得更完整的答案:

http://www.mail-archive.com/clojure@googlegroups.com/msg29338.html

从那里的代码将允许你这样做:

user=> (encode-params {"q" "clojure url"})
"q=clojure+url"
相关文章
相关标签/搜索