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. 记一次springboot整合rabbitMQ的list序列化问题

    问题:平时传一个类的时候都会继承Serializable实现正确传输,这次我把list<Object>直接丢成了message,导致rabbitMQ不能序列化对象.报错 org.sprin ...

  2. 从DDPM到DDIM(四) 预测噪声与后处理

    从DDPM到DDIM(四) 预测噪声与后处理 前情回顾 下图展示了DDPM的双向马尔可夫模型. 训练目标.最大化证据下界等价于最小化以下损失函数: \[\boldsymbol{\theta}^*=\u ...

  3. ansible 部署hadoop

    规划 ansible 节点 ansible controller 镜像rhel 8.2 镜像ansible hadoop 集群 master slave1 slave2 镜像centos 1810 0 ...

  4. Jmeter函数助手14-TestPlanName

    TestPlanName函数获取当前测试计划保存的文件名称.该函数没有参数,直接引用即可${__TestPlanName}.

  5. 【Layui】12 评分 Rate

    文档地址: https://www.layui.com/demo/rate.html 基础样式: <fieldset class="layui-elem-field layui-fie ...

  6. 树莓派3b+ 安装Ubuntu mate18.04系统 配置SSH 、 远程桌面realvnc

    Ubuntu mate  for  树莓派3b+ 系统下载: 下载地址: https://ubuntu-mate.org/download/ 这里用32位系统:(64位也可以的,虽然还是实验阶段的,不 ...

  7. 【转载】 CV往哪卷?李飞飞指出三颗「北极星」:具身智能,视觉推理和场景理解

    原文地址: https://news.cnblogs.com/n/720105/ 新智元报道 编辑:LRS ============================================== ...

  8. 纯css美化滚动条样式

    https://www.emperinter.info/2020/09/20/scrollbar-in-browser/ 自己完善自己博客再Ipad等移动端的菜单时选用了左右滑动的菜单模式!当然就会使 ...

  9. 神经网络之卷积篇:详解卷积步长(Strided convolutions)

    详解卷积步长 卷积中的步幅是另一个构建卷积神经网络的基本操作,让向展示一个例子. 如果想用3×3的过滤器卷积这个7×7的图像,和之前不同的是,把步幅设置成了2.还和之前一样取左上方的3×3区域的元素的 ...

  10. jenkins集成findBugs并生成报告 转

    公司使用jenkins来作为持续构建工具,由于要进行自动化构建.编译.代码走查.打包.今天介绍下 jenkins集成findbugs的经验. 1.首先进入jenkins插件管理页面,下载途中的find ...