webclient post java_java – Spring WebFlux,如何调试我的WebClient POST交换?
我无法理解在构建WebClient请求时我做错了什么.我想了解实际的HTTP请求是什么样的. (例如,将原始请求转储到控制台)
POST /rest/json/send HTTP/1.1
Host: emailapi.dynect.net
Cache-Control: no-cache
Postman-Token: 93e70432-2566-7627-6e08-e2bcf8d1ffcd
Content-Type: application/x-www-form-urlencoded
apikey=ABC123XYZ&from=example%40example.com&to=customer1%40domain.com&to=customer2%40domain.com&to=customer3%40domain.com&subject=New+Sale+Coming+Friday&bodytext=You+will+love+this+sale.
我正在使用Spring5的反应工具来构建API.我有一个实用工具类,它将使用Dyn的电子邮件api发送电子邮件.我想使用新的WebClient类来完成这个(org.springframework.web.reactive.function.client.WebClient)
curl --request POST "https://emailapi.dynect.net/rest/json/send" --data "apikey=ABC123XYZ&from=example@example.com&to=customer1@domain.com&to=customer2@domain.com&to=customer3@domain.com&subject=New Sale Coming Friday&bodytext=You will love this sale."
当我使用真实值在curl中进行调用时,电子邮件正确发送,因此我觉得我正在生成错误的请求.
我的发送命令
public Mono send( DynEmailOptions options )
{
WebClient webClient = WebClient.create();
HttpHeaders headers = new HttpHeaders();
// this line causes unsupported content type exception :(
// headers.setContentType( MediaType.APPLICATION_FORM_URLENCODED );
Mono result = webClient.post()
.uri( "https://emailapi.dynect.net/rest/json/send" )
.headers( headers )
.accept( MediaType.APPLICATION_JSON )
.body( BodyInserters.fromObject( options ) )
.exchange()
.flatMap( clientResponse -> clientResponse.bodyToMono( String.class ) );
return result;
}
我的DynEmailOptions类
import java.util.Collections;
import java.util.Set;
public class DynEmailOptions
{
public String getApikey()
{
return apiKey_;
}
public Set getTo()
{
return Collections.unmodifiableSet( to_ );
}
public String getFrom()
{
return from_;
}
public String getSubject()
{
return subject_;
}
public String getBodytext()
{
return bodytext_;
}
protected DynEmailOptions(
String apiKey,
Set to,
String from,
String subject,
String bodytext
)
{
apiKey_ = apiKey;
to_ = to;
from_ = from;
subject_ = subject;
bodytext_ = bodytext;
}
private Set to_;
private String from_;
private String subject_;
private String bodytext_;
private String apiKey_;
}
webclient post java_java – Spring WebFlux,如何调试我的WebClient POST交换?相关推荐
- Spring Webflux 响应式编程 (二) - WebFlux编程实战
第一章 Reactive Stream 第1节 jdk9的响应式流 就是reactive stream,也就是flow.其实和jdk8的stream没有一点关系.说白了就一个发布-订阅模式,一共只有4 ...
- java中spring的web支持nio,Spring WebClient NIO功能和问题域,与Spring Webflux一起使用
我正在使用最新版本的Spring - Spring 5 . 我正在开发http客户端的WebService"聚合器",有点像路由请求到外部WebServices,接收响应后接收响应 ...
- Spring WebFlux – SpringReact式编程
Spring WebFlux is the new module introduced in Spring 5. Spring WebFlux is the first step towards re ...
- 响应式Spring的道法术器(Spring WebFlux 教程)
Spring WebFlux 2小时快速入门 Spring 5 之使用Spring WebFlux开发响应式应用. lambda与函数式(15min) Reactor 3 响应式编程库(60min) ...
- Spring Webflux简介
1.Spring Webflux介绍 The original web framework included in the Spring Framework, Spring Web MVC, was ...
- 响应式Spring的道法术器(Spring WebFlux 快速上手 + 全面介绍)
1. Spring WebFlux 2小时快速入门 Spring 5 之使用Spring WebFlux开发响应式应用. lambda与函数式(15min) Reactor 3 响应式编程库(60mi ...
- 爸爸又给Spring MVC生了个弟弟叫Spring WebFlux
作者:李新杰 来自:编程新说 情景引入 很早之前,Java就火起来了,是因为它善于开发和处理网络方面的应用. Java有一个爱好,就是喜欢制定规范标准,但自己又不善于去实现. 反倒是一些服务提供商使用 ...
- Spring WebFlux和Spring Cloud开发响应式微服务
作者:Piotr Mińkowski 译者:大萝卜爱上小白菜 原文:https://dzone.com/articles/reactive-microservices-with-spring-webf ...
- corda_使用Spring WebFlux从Corda节点流式传输数据
corda 自上次发布以来已经有一段时间了,但我终于回来了! 由于我仍在我的项目中,因此我将再次撰写有关使用Corda的文章. 这次,我们将不再关注Corda,而是将Spring与Corda结合使用. ...
最新文章
- 1268 和为K的组合
- SAP中如何更改供应商账户组
- 下一个排列Python解法
- java百度结果的正则表达式_java正则表达式
- 3.4 Zend_Db_Table_Row
- HMM, CTC和RNN-Transducer对齐方式的差异
- 浅析vendor_init
- 数据库的核心和基础、DBS三级模式结构、关系模型、数据、数据库、模式、内模式、外模式
- 视频教程-Ps教程之神奇的Photoshop自动化技术-Photoshop
- 有关神经网络的训练算法,深度神经网络训练方法
- app小程序手机端Python爬虫实战12实现自动化退出考研帮app并清空缓存
- arch linux u盘安装,使用U盘安装Arch Linux系统步骤
- js写css字体,js如何写出css动画 ?js写css动画的方法(代码)
- 支持Adobe Photoshop CC 201720182019 的Coolorus 2.5.14 色环插件
- 【Error】chaincode install failed with status: 500 - failed to invoke backing implementation xxx
- 问题:C:\Users\DELL\anaconda3\lib\site-packages\numpy\__init__.py:140: UserWarning
- tensorflow如何做幂律分布_离散概率分布与连续概率分布
- 摇杆怎么映射到键盘_便宜100多的“官方山寨”究竟怎么样?联想拯救者X1游戏手柄体验...
- Linux装docker + rancher
- CSS中固定定位、相对定位、绝对定位以及flex布局高效定位
热门文章
- 80x86 register and memory mode
- 【linux指令】sed指令
- C语言宏定义中#define中的井号#的使用
- ihtml2document能不能根据id获取dom_JavaScript学习笔记(十三)-- DOM(上)
- php项目电影院售票管理系统,电影院售票管理系统
- IDEA下Springcloud框架搭建(一)之服务注册与发现
- (四)训练运行Deep CycleGAN以进行移动风格迁移
- 使用Keras和CNN进行自定义AI人脸识别
- 实例解读Docker Swarm
- 在Python中使用MongoDB