I have installed the recommended plugins and I attach the class files I have made. When I use them to send a post request, I get the below error
java.lang.IllegalStateException: Fail to prepare request body for sending.
The body type is:class data.model.dto.RegisterDto(Kotlin reflection is not available), with Content-Type: application/json. If you expect serialized body, please check that you have installed the corresponding plugin(likeContentNegotiation) and setContent-Typeheader.
at io.ktor.client.plugins.HttpSend$Plugin$install$1.invokeSuspend(HttpSend.kt:88)
HttpClient(CIO) {
install(ContentNegotiation) {
json(Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
})
}
}
@Serializable
data class RegisterDto(
val email: String,
val password: String
)
ApiClient.httpClient.post {
url("http:////192.168.0.104:8090/auth/login")
contentType(ContentType.Application.Json)
body = RegisterDto("[email protected]", "1234567890")
}
Resolved, had to use
setBody(RegisterDto("[email protected]", "1234567890")instead ofbody = RegisterDto("[email protected]", "1234567890")