im trying to make an android app with retrofit library, but it seems like i can't connect into the server. But, i dont really get any specifi reason why is this happening. I already put access_network_state and internet permission on manifest. Also the api works normally when i open it with browser.
Here is my code for retrofit interface
@GET("seasons/now")
suspend fun getCurrentSeason(@Query("page") page: Int = 1): Response<GenericResponse<DataItem>>
And here is my code for instance creation
@Provides
@Singleton
fun provideOkHttp(logger: HttpLoggingInterceptor) = OkHttpClient.Builder()
.addInterceptor(logger)
.connectTimeout(60, TimeUnit.SECONDS)
.build()
@Provides
@Singleton
fun provideJikanApi(okHttpClient: OkHttpClient): JikanApi = Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(okHttpClient)
.build().create(JikanApi::class.java)
CodePudding user response:
Add the following line to the manifest inside your application
android:usesCleartextTraffic="true"
CodePudding user response:
Define domain api.jikan.moe
in network_security_config.xml
.
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="false">
<domain>api.jikan.moe</domain>
</domain-config>
</network-security-config>