Ad
Retrofit Taking Too Long For DNS Resolution
I am using retrofit to make a rest call to "https:/google.com". 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 = "https://google.com";
OkHttpClient httpClient = new OkHttpClient.Builder()
.eventListener(new PrintingEventListener())
.build();
Retrofit client = new Retrofit.Builder().baseUrl(baseURL1).client(httpClient)
.build();
TestInterface testInterface = client.create(TestInterface.class);
Call<ResponseBody> testCall = testInterface.testCall();
System.out.println("Scanning REQUEST 1 (new connection)");
testCall.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Log.i( TAG, "Scanning apiCall end success");
}
@Override
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.
Ad
Answer
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 google.com
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.
Ad
source: stackoverflow.com
Related Questions
- → should I choose reactjs+f7 or f7+vue.js?
- → Phonegap Android write to sd card
- → Local reference jquery script in nanohttpd (Android)
- → Click to navigate on mobile devices
- → How to allow api access to android or ios app only(laravel)?
- → Access the Camera and CameraRoll on Android using React Native?
- → React native change listening port
- → What is the default unit of style in React Native?
- → Google play market autocomplete icon
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → Using Laravel with Genymotion
- → react native using like web-based ajax function
- → react native pdf View
Ad