body property

String body

The body of the request as a string.

This is converted to and from bodyBytes using encoding.

When this is set, if the request does not yet have a Content-Type header, one will be added with the type text/plain. Then the charset parameter of the Content-Type header (whether new or pre-existing) will be set to encoding if it wasn't already set.

To set the body of the request, without setting the Content-Type header, use bodyBytes.


String get body => encoding.decode(bodyBytes);
void body=(String value)


set body(String value) {
  bodyBytes = encoding.encode(value);
  var contentType = _contentType;
  if (contentType == null) {
    _contentType = MediaType('text', 'plain', {'charset':});
  } else if (!contentType.parameters.containsKey('charset')) {
    _contentType = contentType.change(parameters: {'charset':});