【问题标题】:How to set the parameters to test form POST using WebTestClient如何使用 WebTestClient 设置参数以测试表单 POST
【发布时间】:2019-03-24 14:13:07
【问题描述】:

如何测试使用WebTestClient 发布表单。如何设置请求参数?

使用非反应性MockMvc 我可以使用.param(),但WebTestClient 似乎没有类似的东西。

【问题讨论】:

标签: forms spring-webflux spring-test


【解决方案1】:

你需要使用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();

【讨论】:

    猜你喜欢
    • 2020-04-11
    • 2011-11-26
    • 2017-03-29
    • 2010-10-12
    • 2012-04-29
    • 2016-06-30
    • 1970-01-01
    • 2014-01-28
    • 1970-01-01
    相关资源
    最近更新 更多