简体   繁体   English

如何添加自定义标题<String, Integer>到 Spring Boot HttpHeaders?

[英]How to add custom header with <String, Integer> to Spring Boot HttpHeaders?

Currently Spring Boot HttpHeaders header only takes <String, String> pairs.目前 Spring Boot HttpHeaders 标头只需要<String, String>对。 How can I add a header with <String, Long> ?如何添加带有<String, Long>的标题?

I need to integrate with one of the external product API in my Java Program, to access this API, it needs a token header which for this product, all of its APIs only takes Numbers(long).我需要与我的 Java 程序中的一个外部产品 API 集成,要访问这个 API,它需要一个令牌标头,对于这个产品,它的所有 API 只需要数字(长)。 It is so out of ordinary and it gives me a lot headache.这太不寻常了,让我很头疼。 I am using RestTemplate and I've searched a lot place with no luck.我正在使用 RestTemplate 并且我搜索了很多地方都没有运气。

Did any of you have done anything similar to this?你们中有人做过类似的事情吗? Need some help.需要一些帮助。

You can create generic header using MultiValueMap that accepts String as key and Object as value您可以使用接受String作为键和Object作为值的MultiValueMap创建通用标头

MultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
map.add("Header1", 11111);

And then create generic HttpEntity of object type by passing MultiValueMap as headers然后通过将MultiValueMap作为标头传递来创建对象类型的通用HttpEntity

HttpEntity<Object> entity = new HttpEntity<>(map);

System.out.println(entity);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在拦截器 spring 引导上添加自定义 header - Add custom header on interceptor spring boot Spring HttpHeaders-获取授权标头 - Spring HttpHeaders - get Authorization header 如何使用 HttpHeaders 在 spring 引导中下载 excel 文件? - How to download excel file in spring boot using HttpHeaders? 为 Z1D78DC8ED51214E5018B5114AE24 创建自定义 java json spring 引导解析器<string, integer></string,> - Create custom java json spring boot parser for map<string, integer> 使用 Z38008DD81C2F4D7985ECF6E0CE8AF1D1 将自定义 Http header 添加到 SOAP 请求 - Add custom Http header to SOAP request with Spring Boot Spring Boot 中的自定义拦截器【添加 HTTP 请求头】 - Custom interceptor in Spring Boot [ADD HTTP REQUEST HEADER] 自定义标头参数 - Spring Boot - Custom header param - Spring Boot 如何为 Spring Boot 2 添加自定义 MeterRegisty - How to add custom MeterRegisty for Spring Boot 2 如何保存从 spring 引导到 elasticsearch 的字符串列表或 integer 列表 - How to save a String list or integer list from spring boot to elasticsearch 如何在Spring Boot中捕获自定义SOAP Header localPart请求 - How to catch custom SOAP Header localPart Request in Spring Boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM