I have used ktor CIO engine to make API calls. When I am trying to check network calls but URLs are not showing inside Android studio Network inspection. Performance testing team tried to intercept API calls using Fiddler tool but they are also unable to capture API calls.
Do I have to change any settings inside App.
I have added cleartextTrafficPermitted as true for testing for both System and Users.
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
</trust-anchors>
</base-config>
I tried adding cleartextTrafficPermitted inside AndroidManifest file also for testing. But nothing seems to work. Am I missing anything here?
Ktor implementation as below:
@Provides
@Singleton
fun provideHttpClient(): HttpClient = HttpClient(CIO) {
expectSuccess = false
install(ContentNegotiation) {
gson()
}
install(Logging) {
logger = Logger.DEFAULT
level = LogLevel.ALL
}
install(HttpTimeout) {
requestTimeoutMillis = 120000
connectTimeoutMillis = 120000
socketTimeoutMillis = 120000
}
engine {
https {
trustManager = @SuppressLint("CustomX509TrustManager")
object : X509TrustManager {
@SuppressLint("TrustAllX509TrustManager")
override fun checkClientTrusted(p0: Array<out X509Certificate>?, p1: String?) {
}
@SuppressLint("TrustAllX509TrustManager")
override fun checkServerTrusted(p0: Array<out X509Certificate>?, p1: String?) {
}
override fun getAcceptedIssuers(): Array<X509Certificate>? = null
}
}
}
HttpResponseValidator {
validateResponse { response: HttpResponse ->
val statusCode = response.status.value
println("HTTP status: $statusCode")
when (statusCode) {
in 300..399 -> throw RedirectResponseException(response, statusCode.toString())
in 400..499 -> throw ClientRequestException(response, statusCode.toString())
in 500..599 -> throw ServerResponseException(response, statusCode.toString())
}
if (statusCode >= 600) {
throw ResponseException(response, statusCode.toString())
}
}
handleResponseExceptionWithRequest { cause, request ->
println("HTTP status: $cause")
throw cause
}
}
}
I used this code and saw network requests in my network inspector
That network client is
and android-side implementation in KMM is: