post() opens a HTTP connection using the POST method and returns Future<HttpClientRequest>.
So you need to do this:
final client = HttpClient();
final request = await client.post(host, port, path);
request.headers.set(HttpHeaders.contentTypeHeader, "plain/text"); // or headers.add()
final response = await request.close();
Example with jsonplaceholder:
final client = HttpClient();
final request = await client.postUrl(Uri.parse("https://jsonplaceholder.typicode.com/posts"));
request.headers.set(HttpHeaders.contentTypeHeader, "application/json; charset=UTF-8");
request.write('{"title": "Foo","body": "Bar", "userId": 99}');
final response = await request.close();
response.transform(utf8.decoder).listen((contents) {
print(contents);
});
prints
{
"title": "Foo",
"body": "Bar",
"userId": 99,
"id": 101
}
Or you can use http library.
client["keep-alive"] = true