1

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.

Shubham Rohila
  • 366
  • 2
  • 12
  • This seems to hit and append a sub url from any other key. Your get url seems fine. Ca you share some for information? – Insane Developer May 05 '21 at 20:20
  • Can I share some of what? Also yes Get works fine, this whole code was working fine unless just now. Nothing was changed on app side, do you think this problem is with the connecting website? But then I wonder how the Postman call is working. – Shubham Rohila May 05 '21 at 20:23
  • If it used to work, the only thing I can suggest is, to clear IDE cache and restart it. – Insane Developer May 05 '21 at 20:24
  • Ohh no, this is how it happened. My app on my phone was disconnected from IDE since afternoon. Calling worked fine in evening, then at night it just stopped working and Toasted the same error while connecting. Then I just connected to IDE to see the error. I dont think IDE had anything to do with it. My coworker having a copy of app is facing same problem – Shubham Rohila May 05 '21 at 20:28
  • I had solved this problem but did not comment here. I am facing this problem again and now I can at least shout at the person responsible for not putting the solution when found. – Shubham Rohila Nov 13 '21 at 15:27

0 Answers0