readAsString method
Reads the body as a string, decoding it using the specified or detected encoding. Defaults to utf8 if no encoding is provided or detected.
Example
router.post('/api/data', (req) async {
final body = await req.readAsString();
final data = jsonDecode(body);
// Use data...
});
Implementation
Future<String> readAsString({Encoding? encoding, final int? maxLength}) {
encoding ??= body.bodyType?.encoding ?? utf8;
return encoding.decodeStream(read(maxLength: maxLength));
}