I\'m trying to make an post request in flutter with content type as url encoded. When I write body : json.encode(data), it encodes to plain text.
If I
I came here just trying to make an HTTP POST request. Here is an example of how to do that:
import 'dart:convert';
import 'package:http/http.dart';
makePostRequest() async {
final uri = 'http://httpbin.org/post';
final headers = {'Content-Type': 'application/json'};
Map body = {'id': 21, 'name': 'bob'};
String jsonBody = json.encode(body);
final encoding = Encoding.getByName('utf-8');
Response response = await post(
uri,
headers: headers,
body: jsonBody,
encoding: encoding,
);
int statusCode = response.statusCode;
String responseBody = response.body;
}