I cannot recover the data from my Wordpress API with the Retrofit library. The error is : HTTP FAILED: java.net.UnknownHostException: Unable to resolve host "app.divion.fr": No address associated with hostname
ApiClient :
import androidx.appcompat.app.AppCompatActivity;
import retrofit2.Call;
import kotlin.contracts.Returns;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class ApiClient extends AppCompatActivity {
//Adresse de l'Api
public static final String BASE_URL = "https://app.divion.fr/wp-json/api/";
//Retrofit Api Client
private static Retrofit retrofit = null;
public static Retrofit getApiClient(){
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.level(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
.build();
if (retrofit == null){
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
ApiInterface :
package com.example.allomairie.rest;
import java.util.Map;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.QueryMap;
public interface ApiInterface {
// Retrofit Interface
//JSON --> GSON Library --> Java Object
@GET("homepage_api")
Call<Object> getHomepageApi(@QueryMap Map<String, String> params);
}
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Ajout de la permission internet pour les actualités worpdress -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- if you want to load images from a file OR from the internet -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AlloMairie">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Thx ;)
Looks like DNS server cannot recognize the Url you specified. Are you sure https://app.divion.fr/wp-json/api/ is an actual working url? You can copy and paste the url in a web browser and see if it opens a page to verify. If it is not a valid Url, please use a valid one.