Search code examples
haskellposturl-encoding

Haskell: URL encoding for post data


I've been looking at Network.HTTP, but can't find a way to create properly URL encoded key/value pairs.

How can I generate the post data required from [(key, value)] pair list for example? I imagine something like this already exists (perhaps hidden in the Network.HTTP package) but I can't find it, and I'd rather not re-invent the wheel.


Solution

  • Take a look at urlEncodeVars.

    urlEncodeVars :: [(String, String)] -> String
    
    ghci> urlEncodeVars [("language", "Haskell"), ("greeting", "Hello, world!")]
    "language=Haskell&greeting=Hello%2C%20world%21"