body property

String get 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 and appropriate charset parameter.

If request has Content-Type header with MIME media type name text or is an XML MIME type (e.g. application/xml or image/svg+xml) without charset parameter, then the charset parameter will be set to encoding.

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

Implementation

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

Implementation

set body(String value) {
  // IANA defines known media types here:
  // https://www.iana.org/assignments/media-types/media-types.xhtml
  bodyBytes = encoding.encode(value);
  var contentType = _contentType;
  if (contentType == null) {
    _contentType = MediaType('text', 'plain', {'charset': encoding.name});
  } else if (_shouldHaveCharset(_contentType) &&
      !contentType.parameters.containsKey('charset')) {
    _contentType = contentType.change(parameters: {'charset': encoding.name});
  }
}