当前位置:网站首页>When requesting resttemplate, set the request header, request parameters, and request body.
When requesting resttemplate, set the request header, request parameters, and request body.
2022-07-02 06:19:00 【Amoeba】
public static <T> ResponseEntity<T> request(String url,
HttpMethod httpMethod,
Class<T> responseType,
Map<String,String> headers,
Map<String,String> params,
Map<String,String> body) {
// Set request parameters
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
if(CollUtil.isNotEmpty(params)){
params.forEach(paramsMap::add);
}
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url);
URI uri = builder.queryParams(paramsMap).build().encode().toUri();
// Set request header
HttpHeaders httpHeaders = new HttpHeaders();
// Must be set when passing the request body
httpHeaders.add("Content-Type", "application/json");
if( CollUtil.isNotEmpty(headers) ){
headers.forEach(httpHeaders::add);
}
// Set request header and request body
HttpEntity<String> httpEntity = new HttpEntity<>(JSONUtil.toJsonStr(body), httpHeaders);
return restTemplate.exchange(uri,httpMethod,httpEntity,responseType);
}
边栏推荐
- 10 erreurs classiques de MySQL
- Is there a really free applet?
- Use of Arduino wire Library
- On Web server
- Hydration failed because the initial UI does not match what was rendered on the server.问题原因之一
- Replace Django database with MySQL (attributeerror: 'STR' object has no attribute 'decode')
- 链表(线性结构)
- 日志(常用的日志框架)
- Flutter hybrid development: develop a simple quick start framework | developers say · dtalk
- 浏览器原理思维导图
猜你喜欢

I/o impressions from readers | prize collection winners list

深入学习JVM底层(四):类文件结构

Google Go to sea entrepreneurship accelerator registration countdown 3 days, entrepreneurs pass through the guide in advance collection!

From design delivery to development, easy and efficient!

Ruijie ebgp configuration case

Hydration failed because the initial UI does not match what was rendered on the server.问题原因之一

Contest3147 - game 38 of 2021 Freshmen's personal training match_ G: Flower bed

Shenji Bailian 3.53-kruskal

经典文献阅读之--Deformable DETR

Detailed notes of ES6
随机推荐
No subject alternative DNS name matching updates. jenkins. IO found, the reason for the error and how to solve it
Cglib代理-代码增强测试
Contest3145 - the 37th game of 2021 freshman individual training match_ H: Eat fish
Google Go to sea entrepreneurship accelerator registration countdown 3 days, entrepreneurs pass through the guide in advance collection!
RestTemplate请求时设置请求头,请求参数,请求体。
Detailed steps of JS foreground parsing of complex JSON data "case: I"
Compte à rebours de 3 jours pour l'inscription à l'accélérateur de démarrage Google Sea, Guide de démarrage collecté à l'avance!
BGP routing optimization rules and notification principles
Support new and old imperial CMS collection and warehousing tutorials
The official zero foundation introduction jetpack compose Chinese course is coming!
深入学习JVM底层(三):垃圾回收器与内存分配策略
注解和反射详解以及运用
数据科学【九】:SVD(二)
In depth understanding of JUC concurrency (II) concurrency theory
LeetCode 39. Combined sum
让每一位开发者皆可使用机器学习技术
利用传统方法(N-gram,HMM等)、神经网络方法(CNN,LSTM等)和预训练方法(Bert等)的中文分词任务实现
Pbootcms collection and warehousing tutorial quick collection release
Ros2 --- lifecycle node summary
Google play academy team PK competition, official start!