我想使用 SpringBoot 2.1.1.RELEASE 在 RestTemplate 中添加 HttpHeaders
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
但是我遇到了编译错误:
The constructor HttpHeaders() is not
visible
最佳答案
要使用 HttpHeaders headers = new HttpHeaders();
消除编译错误,请确保您没有从 apache http 客户端导入 HttpHeaders
。
import org.apache.http.HttpHeaders;
这将不起作用,因为 HttpHeaders
有私有(private)构造函数。
您的导入声明应该是这样的:
import org.springframework.http.HttpHeaders;
然后您可以使用 add(String headerName, String headerValue)
方法添加 header 。
关于java - 在 Spring Boot 2.1.1.RELEASE 中的 RestTemplate 中添加 Http header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53990356/