1

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
Sergei Mikhailovskii
  • 2,100
  • 2
  • 21
  • 43
  • Based on what i know the base url in Retrofit should end on a slash. Try to have your base url like "omdbapi.com/", and move the api key to your interface as @GET("?apikey=956febbc&t=batman"). Hope this helps. – Daniel Spiess Mar 31 '19 at 20:26
  • 1
    @DanielSpiess unfortunately when I changed in such way that `String BaseUrl = "http://www.omdbapi.com/";` and in interface ` @GET("?apikey=956febbc&t=batman")` nothing is changed – Sergei Mikhailovskii Mar 31 '19 at 20:54
  • Possible duplicate of [Android 8: Cleartext HTTP traffic not permitted](https://stackoverflow.com/questions/45940861/android-8-cleartext-http-traffic-not-permitted) – Zoe Jun 14 '19 at 19:28

1 Answers1

1
String BaseUrl = "http://www.omdbapi.com";

get use query

@GET(".")
Call<Film> getFilms(@Query("apikey") String apikey, @Query("t") String t);

request data apiService.getFilms("956febbc", "batman")

fancyyou
  • 965
  • 6
  • 7