https://kotlinlang.org logo
#ktor
Title
# ktor
t

tylerwilson

11/08/2019, 3:42 PM
I am using Ktor on the client side, using
Copy code
Parameters.apply { append(key, value) }
issue is that it is encoding spaces as ‘+’, whereas I need then as ‘%20’. Anybody know if there is a way to adjust this? Or perhaps (like Retrofit) there could be an ‘appendEncoded()’ type call? Thank you!
Debugging the calls, I see this code in HttpUrlEncoded is being used:
Copy code
fun List<Pair<String, String?>>.formUrlEncodeTo(out: Appendable) {
    joinTo(
        out, "&"
    ) {
        val key = it.first.encodeURLParameter(spaceToPlus = true)
        if (it.second == null) {
            key
        }
        else {
            val value = it.second.toString().encodeURLParameter(spaceToPlus = true)
            "$key=$value"
        }
    }
}
Seems kind of rude to assume we want spaces as pluses. The encodeURLParameter even defaults to false, but this code is overriding that.