org.springframework.web.client.HttpClientErrorException: 401 null

Senthil :

I am calling a service from one module to another module. but it throws an exception:

org.springframework.web.client.HttpClientErrorException: 401 null

POST request for "http://localhost:80../.../...Report" resulted in 401 (null); invoking error handler.

I can able to hit this service from post man directly. But when its called from spring boot module it throws error.

BaseResponseDTO baseResponseDTO = restTemplate.postForObject("http://localhost:80../.../...Report", requestDTO, BaseResponseDTO.class);

error throws in this line

Senthil :
I added authorization headers in MultiValueMap and i added object request in HttpEntity. here i added code.

MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>();
headers.add("Authorization", "bearer "+<TOKEN>);
HttpEntity<MyObject> httpEntityRequest = new HttpEntity<>(myObjectReference, headers);

BaseResponseDTO baseResponseDTO = restTemplate.postForObject("http://localhost:80../.../...Report", httpEntityRequest , BaseResponseDTO.class);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=323984&siteId=1