API can't read body request send by flutter http.post

I tried to send a json data which is populated from hive database using flutter as mobile app and API using Laravel, but my API keep saying that the request is empty.

This is my flutter http.post

Future<void> SendDataBacklog() async {
    var jsonBacklog = jsonEncode(backlogList);

    final response = await http.post(
      Uri.parse('http://109.141.122.292/asmankit-api/api/koko/t1a/input/test'),
      headers: <String, String>{
        'Content-Type': 'application/json; charset=UTF-8',
      },
      body: jsonBacklog,
    );
    if (response.statusCode == 200) {
      //show your outputs
      Hive.box('asmankit_backlog').clear();
      AlertPostBerhasil(context);
    } else {
      print('Backlog data: $jsonBacklog');
      print("response backlog: " + response.body);
      AlertKoneksiFailed(context);
    }
  }

This is my json data

[{
    "tanggal_catat": "2022-12-08 21:28:18",
    "id_mesin": "12",
    "hsd": "11",
    "rpm": "11",
    "tekOli": "11",
    "tempMasuk": "11",
    "tempKeluar": "11",
    "tempMesin": "11",
    "r": "11",
    "s": "11",
    "t": "11",
    "kw": "11",
    "hz": "11",
    "volt": "11",
    "cosQ": "11",
    "age": "testing| Backlog"
},
{
    "tanggal_catat": "2022-12-08 23:22:29",
    "id_mesin": "12",
    "hsd": "99",
    "rpm": "99",
    "tekOli": "99",
    "tempMasuk": "99",
    "tempKeluar": "99",
    "tempMesin": "99",
    "r": "99",
    "s": "99",
    "t": "99",
    "kw": "99",
    "hz": "99",
    "volt": "99",
    "cosQ": "99",
    "age": "testing| Backlog"
}

This is the request response, which say there is no data passed when call the API

response backlog: {"success":false,"message":"Silahkan Isi Data Yang Kosong","data":{"tanggal_catat":["Masukkan Title Post !"],"id_mesin":["Masukkan Title Post !"],"hsd":["Masukkan Content Post !"],"rpm":["Masukkan Content Post !"],"tekOli":["The tek oli field is required."],"tempMasuk":["The temp masuk field is required."],"tempKeluar":["The temp keluar field is required."],"tempMesin":["The temp mesin field is required."],"r":["Masukkan Content Post !"],"s":["Masukkan Content Post !"],"t":["Masukkan Content Post !"],"kw":["Masukkan Content Post !"],"hz":["Masukkan Content Post !"],"volt":["Masukkan Content Post !"],"cosQ":["Masukkan Content Post !"],"kwhProd":["Masukkan Content Post !"],"keterangan":["Masukkan Content Post !"]}}

Last is my flutter mode map toJson

Map<String, String> toJson() => {
        'tanggal_catat': waktuCatat,
        'id_mesin': idMesin,
        'hsd': hsd,
        'rpm': rpm,
        'tekOli': tekOli,
        'tempMasuk': tempMasuk,
        'tempKeluar': tempKeluar,
        'tempMesin': tempMesin,
        'r': r,
        's': s,
        't': t,
        'kw': kw,
        'hz': hz,
        'volt': volt,
        'cosQ': cosQ,
        'age': keterangan + "| Backlog",
      };


Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation