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

coder82

08/03/2021, 2:02 PM
I am sending a get request with username and password for basic authentication in the url, unfortunately the password contains $ sign, how do I disable the url encoding? I cannot send the a password with a $ as it turns into %24, pls help.
only the Apache client does it, so i change client!
but still no solution on this
h

hfhbd

08/03/2021, 2:12 PM
You should never put the password in the url. Only in some browsers, this is converted to the correct header. Other clients, like curl using terminal don't convert it. Please use the correct header in the request builder:
Copy code
get("/") {
    header(HttpHeaders.Authorization, "Basic ${"$username:$password".encodeBase64()}")
}
👍 3
a

Aleksei Tirman [JB]

08/03/2021, 4:03 PM
You can set the value of
urlEncodingOption
property to
<http://UrlEncodingOption.NO|UrlEncodingOption.NO>_ENCODING
to disable encoding. Here is an example:
Copy code
val url = URLBuilder().apply {
    parameters.urlEncodingOption = UrlEncodingOption.NO_ENCODING
    parameters.append("username", "john")
    parameters.append("password", "sec\$ret")
}

println(url.buildString())
👍 2
5 Views