androidkotlinurlencodeurldecode

How can I get the correct format for the link?


It is necessary to convert this address to the correct format, since there is a space between the code id_token and openid accounts, which will not allow to follow the link correctly.

If I understand correctly the first thing I need to do is decode my url and then decrypt it?

https://api.mandarine.sai.com/authorize
    ?client_id=CLIENT_ID
    &response_type=code id_token
    &scope=openid accounts
    &redirect_uri=REDIRECT_URI
    &request=CONSENT_ID

But after I do this, I can't see the full address in the logs and I'm not sure if it's correct.

Here is my log:

[size=270 text=https://api.mandarine.sai.com/authorize?client_id=P1zLA3tA6nYG…]

And here is my code:

operator fun invoke(consentId: String): String {
        val url: String =  "$authorizeUrl?client_id=$clientId&response_type=code id_token&scope=openid accounts&redirect_uri=$redirect_uri&request=$consentId"
        val decodeUrl: String = URLDecoder.decode(url, "UTF-8")
        val encodeUrl: String = decodeUrl.encode().toString()
        return encodeUrl
    }

Solution

  • I can use the replace function, but as for me, this is not quite an elegant solution:

    val authorizeUrl: String = url.replace(" ", "%20")