bodyFields property

Map<String, String> get bodyFields

The form-encoded fields in the body of the request as a map from field names to values.

The form-encoded body is converted to and from bodyBytes using encoding (in the same way as body).

If the request doesn't have a Content-Type header of application/x-www-form-urlencoded, reading this will throw a StateError.

If the request has a Content-Type header with a type other than application/x-www-form-urlencoded, setting this will throw a StateError. Otherwise, the content type will be set to application/x-www-form-urlencoded.

This map should only be set, not modified in place.

Implementation

Map<String, String> get bodyFields {
  var contentType = _contentType;
  if (contentType == null ||
      contentType.mimeType != 'application/x-www-form-urlencoded') {
    throw StateError('Cannot access the body fields of a Request without '
        'content-type "application/x-www-form-urlencoded".');
  }

  return Uri.splitQueryString(body, encoding: encoding);
}
set bodyFields (Map<String, String> fields)

Implementation

set bodyFields(Map<String, String> fields) {
  var contentType = _contentType;
  if (contentType == null) {
    _contentType = MediaType('application', 'x-www-form-urlencoded');
  } else if (contentType.mimeType != 'application/x-www-form-urlencoded') {
    throw StateError('Cannot set the body fields of a Request with '
        'content-type "${contentType.mimeType}".');
  }

  body = mapToQuery(fields, encoding: encoding);
}