Flutter - How to send a POST request using HTTP in Dart?
Checked the following code which worked for me.
Future<Album> createAlbum(String html) async { final http.Response response = await http.post( 'https://www.html2json.com/api/v1', headers: <String, String>{ 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', }, body: html, );
You need to change the Content-type to application/x-www-form-urlencoded; charset=UTF-8
. This should do the trick.
Thanks to DARSH SHAH, I solved this using dio (https://pub.dev/packages/dio).
dynamic response; Dio dio = Dio(); Future<dynamic> test() async { dynamic link = await dio.get( 'https://example.com'); return link; } Future<dynamic> post(dynamic body) async { String _baseUrl = "https://html2json.com/api/v1"; var options = Options( contentType: "application/x-www-form-urlencoded; charset=UTF-8", followRedirects: false, ); final response = await dio.post( _baseUrl, data: body, options: options, ); return response; }FloatingActionButton( onPressed: () async { dynamic responseHTML = await test(); response = await post(responseHTML.data); //This will contain the JSON response },);