Retrofit connecting to different URL instead of base URL

277 views Asked by At

I am trying to connect to a specific BASE_URL but Retrofit throws an error and says cannot connect with BASE_URL/13.127.91.230:80. I dont know what this added 13.127.91.230:80 is

Now I can verify that the latter URL does not work, but why is Retrofit trying to connect to it instead of what was just {baseUrl??

Retrofit Instance:

private static Retrofit retrofit;
    private static final String BASE_URL = "http://{baseUrl}";

    public static Retrofit getRetrofitInstance() {
        if (retrofit == null) {
            retrofit = new retrofit2.Retrofit.Builder()
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
        }
        return retrofit;
    }

The code where I am calling it is

ApiInterface jsonPlaceHolderApi = retrofit2.create(ApiInterface.class);

        jsonPlaceHolderApi.getskuitem(key,sku).enqueue(new Callback<items>() {

            @Override
            public void onResponse(Call<items> call, Response<items> response) {
                if (!response.isSuccessful()) {
                    Toast.makeText(mContext, "Code: "+response.code(), Toast.LENGTH_SHORT).show();
                    
                }
                List<products> products = response.body().getProducts();

                addToFirebase(products);


            }

            @Override
            public void onFailure(Call<items> call, Throwable t)
            {
                
                Log.d("Tag",t.getMessage()+ " "+ t.getLocalizedMessage()+" "+t.getCause());
            }

        });

API interface is:

 @GET("/rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=sku")
    Call<items> getskuitem(@Header("Authorization") String token, @Query("searchCriteria[filter_groups][0][filters][0][value]") String sku);

and finally the Error logged in is when during onFailure is

Failed to connect to {baseURL}/13.127.91.230:80 Failed to connect to {baseURL}/13.127.91.230:80 java.net.ConnectException: failed to connect to {baseURL}/13.127.91.230 (port 80) from /192.168.1.101 (port 46908) after 10000ms: isConnected failed: ECONNREFUSED (Connection refused)

It was working fine before, suddenly started giving problems

I have tried the API call on Postman and it gives the desired response.

0

There are 0 answers