I/O error on POST request for API: HTTP/1.1 header parser received no bytes

31 Views Asked by At

I am calling a client API where I am getting the below error first time. org.springframework.web.client.ResourceAccessException: I/O error on POST request for URL: HTTP/1.1 header parser received no bytes From next time it starts working. I am using Spring Boot 3.2.2 and using restclient to call this API. Below is the code :

ResponseEntity<Response> responseEntity = restClient.post()
            .uri("%s/veriy".formatted(config.getUrl()))
            .header("x-api-key", config.getKey())
            .body(requestBody)
            .retrieve()
            .toEntity(Response.class);

        String statusCode = Objects.requireNonNull(responseEntity.getBody()).getStatusCode();
        if (!SUCCESS.equals(statusCode)){
            logger.info("Invalid Verification Number");
            return null;
        }
        return responseEntity.getBody().getResult();

Please suggest what is the fix for it.

I found online that the HttpVersion needs to be set while calling this API. Can someone suggest how to add httpversion in restclient

0

There are 0 best solutions below