我正在从一个模块调用服务到另一个模块。但这会引发异常:
org.springframework.web.client.HttpClientErrorException:401空
对“ http://localhost:80../.../...Report”的POST请求导致401 (空值);调用错误处理程序。
我可以直接从邮递员那里获得这项服务。 但是,当从spring boot模块调用它时,它将引发错误。
BaseResponseDTO baseResponseDTO = restTemplate.postForObject("http://localhost:80../.../...Report", requestDTO, BaseResponseDTO.class);
此行引发错误
答案 0 :(得分:0)
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);