Flutter: Send form-data for Http GET request

Viewed 407

I need to make a GET request to an API from my Flutter app which request body as form-data.

I tested the API with JSON request body in Postman and it seems to be working fine.

enter image description here

1 Answers

If you are using GET request method there can be two ways to to pass parameters as Query Paremeters or Path Paremeters

Your request dart code would be like

import 'package:http/http.dart' as http;

Future getPatientAppointments() async {
    String appointmentUrl = "$url/api/PatientAppointments/GetMyPatientAppointmentAsDoctor";
    String startDate = "01-05-2021";
    String endDate = "01-05-2021";
    var _response = await http.get(
      Uri.parse("$appointmentUrl?startDate=$startDate&endDate=$endDate"),
    );
    print(_response.body);
}
Related