WebClient 依赖

  <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
WebClient 方法 注解
block() 阻塞式获取响应结果
subscribe() 非阻塞式获取响应结果
exchange() 获取HTTP响应完整内容:HTTP报文中的状态码、headers等信息
retrieve() 只能获取HTTP报文中的Body

WebClient Post请求发送JSON字符串、对象、表单数据

RestTemplate Post请求发送JSON字符串、对象、表单数据

	@Test
void contextLoads3() {
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
//设置请求头
HttpHeaders headers = new HttpHeaders();
//设置参数
LinkedMultiValueMap<String, Object> body = new LinkedMultiValueMap(); body.add("tel", "15333065057");
HttpEntity<LinkedMultiValueMap<String, Object>> entity = new HttpEntity(body, headers);
//请求接口,并接收返回的信息
String s = restTemplate.exchange("http://jsonplaceholder.typicode.com/posts", HttpMethod.POST, entity, String.class).getBody(); System.out.println(s);
}

Spring 之 RestTemplate VS WebClient 发送 HTTP请求的更多相关文章

  1. Web Server 使用WebClient 发送https请求 The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel

    使用WebClient 发送https请求 使用WebClient发送请求时,并且是以https协议: WebClient webClient = new WebClient(); string re ...

  2. SpringBoot26 RestTemplate、WebClient

    1 RestTemplate RestTemplate是在客户端访问 Restful 服务的一个核心类:RestTemplate通过提供回调方法和允许配置信息转换器来实现个性化定制RestTempla ...

  3. JavaWeb 发送post请求的2种方式(form、json)

      JavaWeb 发送post请求的2种方式(form.json) CreationTime--2018年6月20日10点15分 Author:Marydon 前提:通过HttpClient来实现 ...

  4. Spring Cloud Alibaba基础教程:支持的几种服务消费方式(RestTemplate、WebClient、Feign)

    通过<Spring Cloud Alibaba基础教程:使用Nacos实现服务注册与发现>一文的学习,我们已经学会如何使用Nacos来实现服务的注册与发现,同时也介绍如何通过LoadBal ...

  5. 使用RestTemplate发送post请求

    最近使用RestTemplate发送post请求,遇到了很多问题,如转换httpMessage失败,中文乱码等,调了好久才找到下面较为简便的方法: RestTemplate restTemplate ...

  6. WebClient模拟发送Post请求

    WebClient模拟发送Post请求方法: /// <summary> /// 模拟post请求 /// </summary> /// <param name=&quo ...

  7. WebClient以POST方式发送Web请求

    本例使用WebClient以POST方式发送Web请求并下载一个文件,难点是postData的构造,发送Web请求时有的网站要求可能要求 Cookies前后一致.其中application/x-www ...

  8. 使用RestTemplate发送post请求,请求头中封装参数

    最近使用RestTemplate发送post请求,遇到了很多问题,如转换httpMessage失败.中文乱码等,调了好久才找到下面较为简便的方法: RestTemplate restTemplate ...

  9. 【Java SpringBoot】RestTemplate使用postForObject发送请求,接收String类型的response时中文乱码

    https://blog.csdn.net/qq_43758789/article/details/120576717 使用RestTemplate发送PostForObject的时候会出现乱码.这是 ...

  10. 还不知道spring的RestTemplate的妙用吗

    为什么要使用RestTemplate? 随着微服务的广泛使用,在实际的开发中,客户端代码中调用RESTful接口也越来越常见.在系统的遗留代码中,你可能会看见有一些代码是使用HttpURLConnec ...

随机推荐

  1. Python elasticsearch-py类库基础用法

    实践环境 https://pypi.org/project/elasticsearch/ pip install elasticsearch==7.6.0 离线安装包及依赖包下载地址: https:/ ...

  2. 如何免费提取PDF里的图片-pdfimages使用教程

    写在前面 本随笔是非常菜的菜鸡写的.如有问题请及时提出. 可以联系:1160712160@qq.com GitHhub:https://github.com/WindDevil (目前啥也没有 动机 ...

  3. Unity入门学习日记(一)

    UGUI的初步使用 1. Canvas 使用UI的时候,所有的UI元素都作为Canvas的子节点存在于Canvas中,如果创建UI元素时没有Canvas作为父节点,会自动生成一个Canvas,是一位& ...

  4. BCLinux 8.2安装配置图解教程--龙蜥社区国产移动云系统

    社区镜像下载地址:https://openanolis.cn/download 安装参考地址:https://www.osyunwei.com/archives/13017.html 1安装系统 界面 ...

  5. 【Java】找不到此类异常

    Java.lang.classNotFoundException 找不到此类异常: java.lang.ClassNotFoundException: org.springframework.web. ...

  6. 【Linux】Re03

    一.软连接 语法用法 ln -s 源文件或者目录位置 链接名称 [root@localhost ~]# mkdir -p aa/bb/cc/dd [root@localhost ~]# ln -s a ...

  7. ComfyUI插件:ComfyUI layer style 节点(四)

    前言: 学习ComfyUI是一场持久战,而ComfyUI layer style 是一组专为图片设计制作且集成了Photoshop功能的强大节点.该节点几乎将PhotoShop的全部功能迁移到Comf ...

  8. Reinforcement 代码库

    https://github.com/dragen1860?tab=repositories https://github.com/awjuliani?tab=repositories https:/ ...

  9. MindSpore 如何实现一个线性回归 —— Demo示例

    如何使用 MindSpore  实现一个简单的  线性回归呢??? 根据前面的mindspore的基本操作的学习写出了下面的 一个简单的线性回归算法. import mindspore import ...

  10. Linux系统下使用pytorch多进程读取图片数据时的注意事项——DataLoader的多进程使用注意事项

    原文: PEP 703 – Making the Global Interpreter Lock Optional in CPython 相关内容: The GIL Affects Python Li ...