Skip to content

Sending form and multipart data with WebTestClient [SPR-16118] #20666

@spring-projects-issues

Description

@spring-projects-issues

Andy Wilkinson opened SPR-16118 and commented

I'm enjoying the more fluent nature of WebTestClient when compared with MockMvc, but have found that sending a request with form or multipart data body jars a bit. The main problem is that, as far as I can tell, I have to create a MultiValueMap for the data separately and then use BodyInserters.fromMultipartData or BodyInserters.fromFormData, for example:

MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
formData.add("username", "Tester");
this.webTestClient.post().uri("/users").body(BodyInserters.fromFormData(formData))

I'd like to be able to do something like this instead:

this.webTestClient.post().uri("/users").body(BodyInserters.formData().param("username", "Tester"))

Affects: 5.0.1

Sub-tasks:

Issue Links:

Referenced from: commits 14f02d7, 48c2cc1

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions