【发布时间】:2022-08-06 15:34:18
【问题描述】:
我正在使用一个 API,在登录部分 API 只接受“data-form”请求 这是我在多次搜索后找到的解决方案,但它不起作用
@Multipart
@POST(\"oauth/token\")
suspend fun loginUser (@Part (\"username\") username:RequestBody,
@Part (\"password\") password:RequestBody,
@Part(\"grant_type\") grantType:RequestBody):Response<Any>
这是我在 MainActivity 中接受的指令
val pass=\"password\"
lifecycleScope.launch {
val request= movieService.loginUser(
username = userName.toRequestBody(\"text/plain\".toMediaTypeOrNull()),
password = password.toRequestBody(\"text/plain\".toMediaTypeOrNull()),
grantType = pass.toRequestBody(\"text/plain\".toMediaTypeOrNull())
)
Log.i(\"login\",request.body().toString())
}