【发布时间】:2019-03-24 14:13:07
【问题描述】:
如何测试使用WebTestClient 发布表单。如何设置请求参数?
使用非反应性MockMvc 我可以使用.param(),但WebTestClient 似乎没有类似的东西。
【问题讨论】:
-
我正在回答我自己的问题,as is encouraged。
标签: forms spring-webflux spring-test
如何测试使用WebTestClient 发布表单。如何设置请求参数?
使用非反应性MockMvc 我可以使用.param(),但WebTestClient 似乎没有类似的东西。
【问题讨论】:
标签: forms spring-webflux spring-test
你需要使用BodyInserters.fromFormData()来准备请求的body
@Autowired
private WebTestClient client;
private WebTestClient.ResponseSpec response;
...
response = client.mutateWith(csrf()).post().uri("/login")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.body(BodyInserters.fromFormData("username", player)
.with("password", password))
.exchange();
【讨论】: