Skip to content

Instantly share code, notes, and snippets.

@noel-yap
Created October 20, 2015 22:56
Show Gist options
  • Select an option

  • Save noel-yap/e16a6b484d62100cb408 to your computer and use it in GitHub Desktop.

Select an option

Save noel-yap/e16a6b484d62100cb408 to your computer and use it in GitHub Desktop.
def doHttpPost(final String path, final String query) {
final authority = 'example.com'
final url = new URL("http://${authority}/${path}")
final connection = url.openConnection()
connection.with {
setRequestMethod('POST')
doOutput = true
final writer = new OutputStreamWriter(outputStream)
writer.with {
write(query)
flush()
close()
}
connect()
new JsonSlurper().parseText(content.text)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment