title: Http POST request with json content-type in dart:io
body: <p>How to perform HTTP POST using the console dart application (using <code>dart:io</code> or may be <code>package:http</code> library. I do something like that:</p>
  
  
  
  <pre class="lang-dart prettyprint-override"><code>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);
        });
  </code></pre>
  
  <p>but get the following error:</p>
  
  <pre class="lang-dart prettyprint-override"><code>Bad state: Cannot set the body fields of a Request with content-type "application/json".
  </code></pre>