Class FormHttpMessageConverter

java.lang.Object
org.springframework.http.converter.FormHttpMessageConverter
All Implemented Interfaces:
HttpMessageConverter<Object>, SmartHttpMessageConverter<Object>

public class FormHttpMessageConverter extends Object implements SmartHttpMessageConverter<Object>
Implementation of HttpMessageConverter to read and write URL encoded forms. For multipart support, see the MultipartHttpMessageConverter.

This converter can read and write the "application/x-www-form-urlencoded" media type as MultiValueMap<String, String>.

Examples

The following snippet shows how to submit an HTML form using the "application/x-www-form-urlencoded" content type.

RestClient restClient = RestClient.create();

MultiValueMap<String, String> form = new LinkedMultiValueMap<>();
form.add("field 1", "value 1");
form.add("field 2", "value 2");
form.add("field 2", "value 3");
form.add("field 3", 4);

ResponseEntity<Void> response = restClient.post()
  .uri("https://example.com/myForm")
  .contentType(MediaType.APPLICATION_FORM_URLENCODED)
  .body(form)
  .retrieve()
  .toBodilessEntity();
Since:
3.0
Author:
Arjen Poutsma, Rossen Stoyanchev, Juergen Hoeller, Sam Brannen, Brian Clozel
See Also: