Http-POST-request mit json content-type-in dart:io

Wie zum ausführen von HTTP-POST-Konsole mit dem dart-Anwendung (mit dart:io oder kann package:http Bibliothek. Sowas mache ich:

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);
      });

aber bekomme die folgende Fehlermeldung:

Bad state: Cannot set the body fields of a Request with content-type "application/json".
InformationsquelleAutor Roman | 2014-12-19
Schreibe einen Kommentar