import groovy.json.JsonSlurper

try{
String urlParameters="url=parametreleri&burada=yerAlacak"
byte[] postData = urlParameters.getBytes( "UTF-8" )
int postDataLength = postData.length

String request = "http://<SERVICE_IP>:30080/token"

URL url = new URL( request )
HttpURLConnection conn= (HttpURLConnection) url.openConnection()
conn.setDoOutput(true)
conn.setRequestMethod("POST")
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded")
conn.setUseCaches(false)
try{
  DataOutputStream wr = new DataOutputStream(conn.getOutputStream())
  wr.write( postData )
  wr.close()
}catch(Exception e){
  requestErrorMessageToTargetAPI=e.getMessage()
}
def json = conn.inputStream.withCloseable { inStream -> new JsonSlurper().parse( inStream as InputStream ) }
  requestHeaderMapToTargetAPI.put("Authorization" ,"Bearer "+json.access_token)
}
catch(Exception e){
  requestErrorMessageToTargetAPI=e.getMessage()
}
GROOVY