Skip to content

Login接口二次URL encode #2

@DazeCake

Description

@DazeCake

AuthAPI中的login接口存在二次编码问题

例如密码为aaa@111,最终拼接的请求url为baseUrl/account/aaa%2540111

其中,%25对应%,而%40对应@

尝试修改具体登录函数实现

suspend fun login(callback: (WebsiteUser)->Unit){
        progressDialog.value = true
        "eamil: ${email.value}".toast()
        password.value.toast()
        // chaneg: 尝试不进行编码直接传递
        // val passStr =  URLEncoder.encode(password.value, "utf-8")
        val passStr =  password.value
        val res = Net.auth.login(email.value, passStr) .awaitResponseOK()
        res.onSuccessful {
            it?.let { data ->
                progressDialog.value = false
                callback(data)
            }
        }.onFailed { _, msg ->

            showError(msg)
        }
    }

发现最终请求直接不对特殊字符进行编码

而修改login接口

@GET("Auth/{email}/{password}")
    fun login(@Path("email", encoded = false) email: String,
              // change: 将encoded设置为true
              @Path("password", encoded = true) password: String
    ): Call<Response<WebsiteUser>>

可以达到预期并正常登录

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions