I have the following code:
private static final String Tag = "DataUtil";
static List<Film> generateFilms(){
Log.i(Tag, "In generate films");
List <Film> films = new ArrayList<>();
String BaseUrl = "http://www.omdbapi.com/?apikey=956febbc&";
Retrofit.Builder builder = new Retrofit.Builder().baseUrl(BaseUrl)
.addConverterFactory(GsonConverterFactory.create());
OkHttpClient.Builder httpClient = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS);
Retrofit retrofit = builder.build();
APIService apiService = retrofit.create(APIService.class);
final Call<List<Film>> filmsCall = apiService.getFilms();
filmsCall.enqueue(new Callback<List<Film>>() {
@Override
public void onResponse(Call<List<Film>> call, Response<List<Film>> response) {
if (response.isSuccessful()){
Log.i(Tag, response.body().get(0).getTitle());
}
else {
Log.i(Tag, "Response code: "+response.code());
}
}
@Override
public void onFailure(Call<List<Film>> call, Throwable t) {
Log.i(getClass().getSimpleName(), "Error: "+t);
}
});
return films;
}
This code should get data form this site. Here's the interface, which is used for getting data (in this way I get infromation about Batman film):
public interface APIService {
@GET("t=batman")
Call<List<Film>> getFilms();
}
Line Log.i(Tag, response.body().get(0).getTitle())
doesn't add any lines to logger => there's no data in response. At the same time, lines Log.i(Tag, "Response code: "+response.code()); ΠΈ Log.i(getClass().getSimpleName(), "Error: "+t)
don't add anything either. So, what's the matter?
UPD
When I added Interceptor I found the following line in logcat:
I/: Error: java.net.UnknownServiceException: CLEARTEXT communication to www.omdbapi.com not permitted by network security policy