WebServices not working with retrofit but working properly in Postman

Viewed 42

I have webservices hosted on server but I am using retrofit to fetch data from the server but When I am running my app it is showing exception Unresolve host but when I am using the same Url in Postman and browser it is working fine.I have also add Internet permission in app manifest file.

Below is my code:

RetrofitClient.java

public class RetrofitClient {

private static Retrofit retrofit = null;

public static Retrofit getInstance(){

    OkHttpClient okHttpClient = new OkHttpClient.Builder()
            .connectTimeout(22, TimeUnit.SECONDS)
            .readTimeout(22, TimeUnit.SECONDS)
            .writeTimeout(22, TimeUnit.SECONDS)
            .build();

    if(retrofit == null)
        retrofit = new Retrofit.Builder()
                .baseUrl("https://adbhutbharat.com/")
                .addConverterFactory(GsonConverterFactory.create(new GsonBuilder().setLenient().create()))
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .client(okHttpClient)
                .build();

    return retrofit;
  }

}

ApiService.java

public interface ApiService {

@GET("app/getAgents.php")
Call<List<Agents>> allAgents();

}

The above endpoint is working properly in postman and browser but not when requesting using retrofit in android to fetch data.

Someone please let me know how to resolve this error any help would be appreciated.

THANKS

0 Answers
Related