0

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

4
  • It sounds like a problem with OkHttp or DNS rather than with Spring Framework. Do other clients, such as curl on the command line, ever fail due to an unknown host? Commented Jun 29, 2023 at 17:24
  • command line curl is fine. How do I tell if it's a client or dns problem? Commented Jun 29, 2023 at 21:29
  • I'd search for some existing questions about intermittent java.net.UnknownHostException. For example, this question has an answer with some suggestions for diagnosing a similar problem. Commented Jun 30, 2023 at 8:03
  • Thanks, solved follow this serverfault.com/questions/578082/… Commented Jul 5, 2023 at 15:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.