Search code examples
flutterhttpdio

How make a http post with Dio using data raw in flutter?


I'm trying to do a dio post request and I need to specify the body as raw-data Post

enter image description here

Response response = await (await init()).post(url, data: {
        "token": token,
        "code": formol}
        );


Solution

  • Try to encode it as a Json:

    var json =  {
      "code": "xxxxxxxxx",
      "token": "-------------",
    }; 
    ...
    Response response = await _dio.post(url,
      options: Options(headers: {
        HttpHeaders.contentTypeHeader: "application/json",
      }),
      data: jsonEncode(json),
    );