Praveen Kumar
07/04/2023, 12:21 PMJames
07/04/2023, 12:26 PMJames
07/04/2023, 12:27 PMPraveen Kumar
07/04/2023, 12:29 PMAleksei Tirman [JB]
07/04/2023, 12:39 PMContent-Type: text/html; charset=UTF-8
instead of the expected Content-Type: application/json
.James
07/04/2023, 12:40 PMJames
07/04/2023, 12:41 PMPraveen Kumar
07/04/2023, 12:49 PMJames
07/04/2023, 1:00 PMPraveen Kumar
07/04/2023, 1:09 PM//@Composable
//fun ProductListView() {
// val scope = rememberCoroutineScope()
// var products by remember {
// mutableStateOf(emptyList<engineer_status>())
// }
// val context = LocalContext.current
// LaunchedEffect(true) {
// scope.runCatching {
// GetProductsUseCase().execute(Unit)
// }.onSuccess { remoteProducts ->
// Toast.makeText(context, "tag1$remoteProducts", Toast.LENGTH_SHORT).show()
//
// if (remoteProducts.isEmpty()){
// products = remoteProducts
// }else{
// Toast.makeText(context, "tag2$remoteProducts", Toast.LENGTH_SHORT).show()
// }
// }.onFailure {
// Log.d("Failed", "Network error$it")
// }
// }
//
// Scaffold(topBar = {
// TopAppBar {
// Row(modifier = Modifier.padding(10.dp)) {
// Text(text = "Products")
// }
// }
// }) { defaultPadding ->
// LazyColumn(modifier = Modifier.padding(defaultPadding)) {
items(products) { product ->
ProductItemView(product)
}
}
}
}
this is my full code of calling API using KtorPraveen Kumar
07/04/2023, 1:10 PMAleksei Tirman [JB]
07/04/2023, 1:21 PMtext/html
content type:
HttpClient() {
install(ContentNegotiation) {
register(ContentType.Text.Html, KotlinxSerializationConverter(Json))
}
}
Praveen Kumar
07/04/2023, 1:22 PMAleksei Tirman [JB]
07/04/2023, 1:24 PMPraveen Kumar
07/04/2023, 1:26 PMPraveen Kumar
07/04/2023, 1:27 PMclass GetProductsUseCase: BaseUseCase<Unit, List<engineer_status>>() {
override suspend fun execute(request: Unit): List<engineer_status> {
val response = <http://networkClient.post|networkClient.post>("<https://cmms.auswegprime.com/Api/get_plant_engineer_status_list>")
return response.body()
}
}
this is the commanMain http client initializationPraveen Kumar
07/04/2023, 1:27 PMactual fun httpClient(config: HttpClientConfig<*>.() -> Unit) = HttpClient(OkHttp) {
config(this)
engine {
config {
retryOnConnectionFailure(true)
connectTimeout(0, TimeUnit.SECONDS)
}
}
}
this is for androidAleksei Tirman [JB]
07/04/2023, 1:28 PMContentNegotiation
plugin is installed.Praveen Kumar
07/04/2023, 1:29 PMexpect fun httpClient(config: HttpClientConfig<*>.() -> Unit = {}): HttpClient
val networkClient: HttpClient = httpClient {
install(ContentNegotiation) {
json(Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
})
}
}
HereAleksei Tirman [JB]
07/04/2023, 1:31 PMContentNegotiation
plugin:
register(ContentType.Text.Html, KotlinxSerializationConverter(Json))
Praveen Kumar
07/04/2023, 1:45 PMPraveen Kumar
07/04/2023, 1:45 PMAleksei Tirman [JB]
07/04/2023, 1:48 PMPraveen Kumar
07/04/2023, 1:50 PMexpect fun httpClient(config: HttpClientConfig<*>.() -> Unit = {}): HttpClient
val networkClient: HttpClient = httpClient {
install(ContentNegotiation) {
json(Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
register(ContentType.Text.Html, KotlinxSerializationConverter(Json))
})
}
}
this is the code. and, the error is
io.ktor.serialization.JsonConvertException: Illegal inputAleksei Tirman [JB]
07/04/2023, 1:50 PMJson { ... }
instead of just Json
from my example.Aleksei Tirman [JB]
07/04/2023, 1:51 PMval networkClient: HttpClient = httpClient {
install(ContentNegotiation) {
register(ContentType.Text.Html, KotlinxSerializationConverter(Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
}))
json(Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
})
}
}
Praveen Kumar
07/04/2023, 2:04 PMi put this code
val networkClient: HttpClient = httpClient {
install(ContentNegotiation) {
register(ContentType.Text.Html, KotlinxSerializationConverter(Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
}))
json(Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
})
}
}
again i get this error
io.ktor.serialization.JsonConvertException: Illegal inputAleksei Tirman [JB]
07/05/2023, 8:20 AMAleksei Tirman [JB]
07/05/2023, 8:24 AMLubaki Josué
09/24/2024, 8:37 AMktorVersion = "2.3.2"