Created
August 30, 2022 11:43
-
-
Save lonniev/e96fc9216bea1bea1bd05cf2a5ad62a6 to your computer and use it in GitHub Desktop.
Make an HTTP Post call in Groovy and parse the JSON response
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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