Retrofit Taking Too Long For DNS Resolution

- 1 answer

I am using retrofit to make a rest call to "https:/". The first request is taking too long.

I tried searching on the net to find a solution, but I was not able to find any.

Below is the code snippet:

    String baseURL1 = "";
    OkHttpClient httpClient = new OkHttpClient.Builder()
                .eventListener(new PrintingEventListener())
    Retrofit client = new Retrofit.Builder().baseUrl(baseURL1).client(httpClient)
    TestInterface testInterface = client.create(TestInterface.class);
    Call<ResponseBody> testCall = testInterface.testCall();

    System.out.println("Scanning REQUEST 1 (new connection)");
    testCall.enqueue(new Callback<ResponseBody>() {
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            Log.i( TAG, "Scanning apiCall end success");

        public void onFailure(Call<ResponseBody> call, Throwable t) {
            Log.i( TAG, "Scanning apiCall end failed");

I am using the latest version of retrofit:

implementation 'com.squareup.retrofit2:retrofit:2.6.0'

The log statements with EventListener:

REQUEST 1 (new connection)
0.000 callStart
0.007 dnsStart
5.048 dnsEnd
5.049 connectStart
5.056 secureConnectStart
5.106 secureConnectEnd
5.108 connectEnd
5.109 connectionAcquired
5.110 requestHeadersStart
5.112 requestHeadersEnd
5.196 responseHeadersEnd
5.197 responseBodyStart
REQUEST 1 (new connection) end success

Any help is greatly appreciated.



You need to check your Internet connection and DNS server's used by the device you are running the above code. Try to run the dns resolution for using another DNS resolver client, and see if it is really the issue with retrofit. As i am guessing its not at retrofit level but your network level.