如何使用控制台dart应用程序执行HTTP POST(使用dart:io或可能是package:http库.我这样做:
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);
});
Run Code Online (Sandbox Code Playgroud)
但是得到以下错误:
Bad state: Cannot set the body fields of a Request with content-type "application/json".
Run Code Online (Sandbox Code Playgroud)