fix: use java.net.URLEncoder for form encoding (removes Ktor FormDataContent dependency), simplify postForm to use Map<String, String>
This commit is contained in:
parent
b342ae85c6
commit
26ebfe132c
@ -79,11 +79,11 @@ class BricksHttp(private val context: BricksContext? = null) {
|
|||||||
*/
|
*/
|
||||||
suspend fun postForm(
|
suspend fun postForm(
|
||||||
url: String,
|
url: String,
|
||||||
form: Parameters,
|
form: Map<String, String>,
|
||||||
authToken: String = ""
|
authToken: String = ""
|
||||||
): String {
|
): String {
|
||||||
val formBody = form.flattenEntries().joinToString("&") { (k, v) ->
|
val formBody = form.entries.joinToString("&") { (k, v) ->
|
||||||
"${encodeURLParameter(k)}=${encodeURLParameter(v)}"
|
"${java.net.URLEncoder.encode(k, "UTF-8")}=${java.net.URLEncoder.encode(v, "UTF-8")}"
|
||||||
}
|
}
|
||||||
val response = client.post(url) {
|
val response = client.post(url) {
|
||||||
contentType(ContentType.Application.FormUrlEncoded)
|
contentType(ContentType.Application.FormUrlEncoded)
|
||||||
|
|||||||
@ -55,7 +55,9 @@ class SageClient {
|
|||||||
_loginError.value = null
|
_loginError.value = null
|
||||||
try {
|
try {
|
||||||
val url = "$baseUrl/rbac/user/userpassword_login.dspy"
|
val url = "$baseUrl/rbac/user/userpassword_login.dspy"
|
||||||
val formBody = "username=${encodeURLParameter(username)}&passwd=${encodeURLParameter(password)}"
|
val encodedUser = java.net.URLEncoder.encode(username, "UTF-8")
|
||||||
|
val encodedPass = java.net.URLEncoder.encode(password, "UTF-8")
|
||||||
|
val formBody = "username=$encodedUser&passwd=$encodedPass"
|
||||||
|
|
||||||
val response = client.post(url) {
|
val response = client.post(url) {
|
||||||
contentType(ContentType.Application.FormUrlEncoded)
|
contentType(ContentType.Application.FormUrlEncoded)
|
||||||
@ -138,7 +140,7 @@ class SageClient {
|
|||||||
path: String,
|
path: String,
|
||||||
params: Map<String, String> = emptyMap(),
|
params: Map<String, String> = emptyMap(),
|
||||||
method: String = "GET",
|
method: String = "GET",
|
||||||
formBody: String = "",
|
formBody: Map<String, String> = emptyMap(),
|
||||||
jsonBody: JsonObject? = null
|
jsonBody: JsonObject? = null
|
||||||
): Result<JsonObject> = mutex.withLock {
|
): Result<JsonObject> = mutex.withLock {
|
||||||
try {
|
try {
|
||||||
@ -155,8 +157,11 @@ class SageClient {
|
|||||||
setBody(jsonBody)
|
setBody(jsonBody)
|
||||||
}
|
}
|
||||||
formBody.isNotEmpty() -> {
|
formBody.isNotEmpty() -> {
|
||||||
|
val bodyStr = formBody.entries.joinToString("&") { (k, v) ->
|
||||||
|
"${java.net.URLEncoder.encode(k, "UTF-8")}=${java.net.URLEncoder.encode(v, "UTF-8")}"
|
||||||
|
}
|
||||||
contentType(ContentType.Application.FormUrlEncoded)
|
contentType(ContentType.Application.FormUrlEncoded)
|
||||||
setBody(formBody)
|
setBody(bodyStr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user