How to perform HTTP POST using the console dart application (using dart:io
or may be package:http
library. I do something like that:
import 'package:http/http.dart' as http;
import 'dart:io';
http.post(
url,
headers: {HttpHeaders.CONTENT_TYPE: "application/json"},
body: {"foo": "bar"})
.then((response) {
print("Response status: ${response.statusCode}");
print("Response body: ${response.body}");
}).catchError((err) {
print(err);
});
but get the following error:
Bad state: Cannot set the body fields of a Request with content-type "application/json".