hi everyone ! im facing a problem in ktor Client side I build a ktor server thats running correctly but when im making a simple GET request it not working (throwing Exception)
Copy code
override suspend fun getAllMessages(chatId : String): MessageDto {
return try {
val url = URLBuilder().apply {
takeFrom(MessageServices.BASE_URL)
path("getMessages")
parameters.append("id", chatId)
}.build()
Log.d("TAG", "getAllMessages: url is -> ${url}")
httpClient.get<MessageDto>(url)
} catch (e: Exception) {
// Handle other exceptions (e.g., network issues)
Log.d("TAG", "getAllMessages: Not GETTING DATA")
e.printStackTrace()
MessageDto("Not Getting Data returning Empty List", emptyList())
}
}
Harpreet Singh.8052
02/02/2024, 6:34 PM
Logger showing this and i also tryed with retrofit to double check that server realy working fine and retrofit returning expected response but i dont know whats wrong with this ktor code that i write , help!!!!
c
Chrimaeon
02/02/2024, 8:39 PM
What does the stacktrace say? How is your MesssageDto setup?
I suspect a deserialization error.
h
Harpreet Singh.8052
02/03/2024, 10:50 AM
Yes , it's a deserialization error After spending a lot of time i figured out I did a mistake on the server side I'm returning a (Json.encodeToString) It working with retrofit but in ktor Clint side I need to accept it in (Content type.Any ) but I simply change the server side so that it will return Json on every request