Clojure building of URL from constituent parts

后端 未结 5 1203
余生分开走
余生分开走 2021-02-07 17:46

In Python I would do the following:

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

>>> url = \"http://sta         


        
5条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-07 18:20

    Here's one way:

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

    I know this is not exactly the same as your Python snippet though. Please see the following post from the Clojure mailing list for a more complete answer:

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

    The code from there will allow you to do this:

    user=> (encode-params {"q" "clojure url"})
    "q=clojure+url"
    

提交回复
热议问题