gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 06:24:54 25 4
gpt4 key购买 nike

我正在从一个模块调用一个服务到另一个模块。但它抛出一个异常:

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

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

我可以直接从 postman 那里点击这项服务。但是当它从 spring boot 模块调用时它会抛出错误。

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

这一行抛出错误

最佳答案

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

关于java - org.springframework.web.client.HttpClientErrorException : 401 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57461906/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com