org.springframework.web.client.HttpClientErrorException:401ヌル

Senthilさん:

私は1つのモジュールから別のモジュールにサービスを呼び出しています。しかし、それは例外をスローします。

org.springframework.web.client.HttpClientErrorException:401ヌル

以下のためのPOSTリクエスト" はhttp:// localhost:80に.. / ... / ...レポート " 401(ヌル)が生じました。エラーハンドラを呼び出します。

私は直接ポストマンからこのサービスを打つことができることができます。その春のブートモジュールから呼び出された場合でも、エラーがスローされます。

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

エラーは、このラインでスロー

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);

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=331426&siteId=1