0

I am trying to access external API from spring boot application in my local machine using external API's username and password but every times its giving error 'org.springframework.web.client.ResourceAccessException: I/O error on POST request for https url "abc.com/api/records": Connection timed out: connect; nested exception is java.net.ConnectException: Connection timed out: connect'.

below is code

public response getDetails(Request requestBody) {
        log.info("getDetails execution started");
        Response responseEntity = null;
        try {
            restTemplate.getInterceptors().add(new BasicAuthorizationInterceptor(apiUsr, psswd));
            responseEntity = restTemplate.postForObject(baseUrl + RECORD_API, requestBody, Response.class);
            log.info("Response:" + responseEntity.toString());
        } catch (Exception exception) {
            log.error(exception.toString());
        }
        return responseEntity;
    }

What could be the reason ?

Rahul
  • 111
  • 3
  • 13
  • This is a really bad way to add an interceptor. Each call will add a new interceptor... You should configure it once in your configuration, not add it each time. Nonetheless the error seems that you either cannot connect or cannot read the data. So no access or your server is slow in generating a response. However I do suspect some firewall/proxy issue. – M. Deinum Jul 11 '23 at 18:44

0 Answers0