gpt4 book ai didi

java - 在 Spring Boot 2.1.1.RELEASE 中的 RestTemplate 中添加 Http header

转载 作者:行者123 更新时间:2023-12-02 10:25:27 27 4
gpt4 key购买 nike

我想使用 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/

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