I have a problem with a Springframework project. I make a call with OkHttpClient and sometimes I get the error java.net.UnknownHostException: www.strava.com: Name or service not known
I tried to insert a 1 minute timeout thinking of solving the problem but if the call fails it fails after a few seconds The call is made successfully a few times and other times the described error returns, but the call is always the same...
String STRAVA_URL = "https://www.strava.com/"
String url = StravaConfig.STRAVA_URL + "/api/v3/oauth/token";
RequestBody requestBody = new FormBody
.Builder()
.add("client_id", StravaConfig.CLIENT_ID)
.add("client_secret", StravaConfig.CLIENT_SECRET)
.add("grant_type", "refresh_token")
.add("refresh_token", account.getStravaRefreshToken())
.build();
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(1, TimeUnit.MINUTES)
.build();
Request request = new Request.Builder()
.method("POST", requestBody)
.url(url)
.build();
Call call = client.newCall(request);
Response response = null;
try {
response = call.execute();
...
} catch (Exception e) {
//HERE THE ERROR
e.printStackTrace();
return e.toString();
}`
Solved Follow this https://serverfault.com/questions/578082/java-and-etc-resolv-conf-dns-server-failover