In the Yesod ecosystem, what is the best way to urlencode some Text?

牧云@^-^@ 提交于 2019-12-05 06:42:10
Michael Snoyman

Unfortunately, due to the complexity of URL escaping, the real answer is "it depends." There are slightly different rules for the percent encoding of path segments and query strings, for example.

I don't know exactly what you're trying to encode, but I'd recommend sticking to the http-types package. One place to start would be urlEncode, though there are many other functions in that packages (such as encodePathSegments mentioned by @jamshidh) which are worth looking at.

As I understand it, URI encoding is complicated. However for my simple case, I was able to get by with the uri-encode package.

All I needed was:

encode :: String -> String

As you can imagine, all it does it take a string, and give you back the URI-encoded version.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!