Skip to content

Instantly share code, notes, and snippets.

@lonniev
Created August 30, 2022 11:43
Show Gist options
  • Select an option

  • Save lonniev/e96fc9216bea1bea1bd05cf2a5ad62a6 to your computer and use it in GitHub Desktop.

Select an option

Save lonniev/e96fc9216bea1bea1bd05cf2a5ad62a6 to your computer and use it in GitHub Desktop.
Make an HTTP Post call in Groovy and parse the JSON response
signInPost = new URL( "http://some.host.com/login" ).openConnection()
message = '{ "username": "email", "password": "somepass", "rememberMe": false }'
signInPost.setDoOutput( true )
signInPost.setRequestProperty( "Content-Type", "application/json" )
signInPost.getOutputStream().write( message.getBytes( "UTF-8" ) )
signInPost.getResponseCode()
j = new groovy.json.JsonSlurper().parseText( signInPost.getInputStream().getText() )
j.resources.token
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment