public TokenCredentials requestServiceTicket(final String serviceURL, final CasRestProfile profile, final WebContext context) {
        HttpURLConnection connection = null;
        try {
            val endpointURL = new URL(configuration.computeFinalRestUrl(context));
            val ticketURL = new URL(endpointURL, endpointURL.getPath() + "/" + profile.getTicketGrantingTicketId());

            connection = HttpUtils.openPostConnection(ticketURL);
            val payload = HttpUtils.encodeQueryParam("service", serviceURL);

            val out = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream(), StandardCharsets.UTF_8));
            out.write(payload);
            out.close();

            val responseCode = connection.getResponseCode();
            if (responseCode == HttpConstants.OK) {
                try (var in = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
                    return new TokenCredentials(in.readLine());
                }
            }
            throw new TechnicalException("Service ticket request for `" + profile + "` failed: " +
                    HttpUtils.buildHttpErrorMessage(connection));
        } catch (final IOException e) {
            throw new TechnicalException(e);
        } finally {
            HttpUtils.closeConnection(connection);
        }
    }
<p>requestServiceTicket.</p>

@param serviceURL a {@link String} object
@param profile a {@link CasRestProfile} object
@param context a {@link WebContext} object
@return a {@link TokenCredentials} object
pac4j-cas/src/main/java/org/pac4j/cas/client/rest/AbstractCasRestClient.java