Groovy web console

subscribe to the feed Subscribe
to this
site
urlencoding yo (via #groovywebconsole)
tweet this snippet Tweet
this
script

urlencoding yo

Published 3 months ago by Anonymous
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
import java.net.URLEncoder

String encode(String str) { URLEncoder.encode(str, "utf-8") }

Map bodyValues = [
    key: "a_key_yo",
    dev_id: "My_Dev_id",
    events: '[{"time":1490158294520,"event":"signed_in & something else","properties":{}}]',
];

println bodyValues.collect { key, value ->
    "${encode(key)}=${encode(value)}"
}.join("&")