1 Future<HttpClientResponse> foo() async {
2 Map<String, dynamic> jsonMap = {
3 'homeTeam': {'team': 'Team A'},
4 'awayTeam': {'team': 'Team B'},
5 };
6 String jsonString = json.encode(jsonMap); // encode map to json
7 String paramName = 'param'; // give the post param a name
8 String formBody = paramName + '=' + Uri.encodeQueryComponent(jsonString);
9 List<int> bodyBytes = utf8.encode(formBody); // utf8 encode
10 HttpClientRequest request =
11 await _httpClient.post(_host, _port, '/a/b/c');
12 // it's polite to send the body length to the server
13 request.headers.set('Content-Length', bodyBytes.length.toString());
14 // todo add other headers here
15 request.add(bodyBytes);
16 return await request.close();
17 }
18
1 Map<String, String> body = {
2 'name': 'doodle',
3 'color': 'blue',
4 'homeTeam': json.encode(
5 {'team': 'Team A'},
6 ),
7 'awayTeam': json.encode(
8 {'team': 'Team B'},
9 ),
10 };
11
12 Response r = await post(
13 url,
14 body: body,
15 );
16