Ivan Carracedo Asensio
01/24/2024, 12:56 PM@POST("auth/signup-user")
suspend fun register(
@Body registerUser: RegisterUser,
): Response<RemoteUser>
But I'm getting this error making the request:
The body type is: class com.example.shared.data.remote.models.LoginUser, with Content-Type: null.
My httpClient:
Ktorfit.Builder().httpClient(Engine) {
configurePlatform()
expectSuccess = true
install(HttpTimeout) {
connectTimeoutMillis = 30.seconds.inWholeMilliseconds
requestTimeoutMillis = 30.seconds.inWholeMilliseconds
socketTimeoutMillis = 2.minutes.inWholeMilliseconds
}
install(HttpRequestRetry) {
retryOnServerErrors(maxRetries = 5)
retryOnExceptionIf(maxRetries = 5) { _, cause ->
cause is TimeoutCancellationException ||
cause is CancellationException ||
cause is kotlinx.coroutines.CancellationException
}
exponentialDelay()
}
install(ContentNegotiation) {
json(
Json {
isLenient = false
prettyPrint = true // Useful for debugging
ignoreUnknownKeys = true
classDiscriminator = "type"
// serializersModule =
},
contentType = ContentType.Application.Json
)
}
install(Logging) {
level = LogLevel.ALL
logger =
object : Logger {
override fun log(message: String) {
co.touchlab.kermit.Logger.i("HttpClient") { message }
}
}
}
}
Where should I tell ktorfit(or ktor) that the Body has to be sent as Json? As usual
Thanks in advanceIvan Carracedo Asensio
01/24/2024, 1:25 PMdefaultRequest {
header("Content-Type", "application/json; charset=utf-8")
}
To the httpClient, but I don't know if that's the best way, because I'm not always sending Json, only in the @ POST'sian.shaun.thomas
01/24/2024, 2:36 PM@Headers("Content-Type: application/json")
Ivan Carracedo Asensio
01/24/2024, 5:56 PM