i am working with Retrofit library on my project, but it seems that Retrofit block non https requests.
I tried by adding in the application
tag in Manifest.xml
android:usesCleartextTraffic="true"
but didn't work, i also tried another solution by adding under res/xml
a security confing file:
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">http://my subdomain/</domain>
</domain-config>
</network-security-config>
and link it in application
tag in the Manifest.xml :
android:networkSecurityConfig="@xml/network_security_config"
both of the solution didn't work. how can i avoid this error ?
NB: my code works fine when i test with https
request, and for testing purposes we are working in a subdomain which use http
.
Just was having this exact problem, not sure if the solution for you will be the same. But in my case I was using okhttp3
as my http client, and when building my client I had to specify the connection specs like so:
val specs = listOf(ConnectionSpec.CLEARTEXT, ConnectionSpec.MODERN_TLS)
client.connectionSpecs(specs)
Previously I was only setting MODERN_TLS
, so in order to allow my library to accept http connections I had to add the CLEARTEXT
spec
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With