【问题标题】:Flutter: Send form-data for Http GET requestFlutter:为 Http GET 请求发送表单数据
【发布时间】:2022-01-18 21:59:01
【问题描述】:

我需要从我的 Flutter 应用程序向 API 发出 GET 请求,请求正文为表单数据。

我在 Postman 中使用 JSON 请求正文测试了 API,它似乎工作正常。

【问题讨论】:

标签: flutter api


【解决方案1】:

如果您使用 GET 请求方法,则可以通过两种方式将参数作为 查询参数路径参数

你的请求 dart 代码会是这样的

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);
}

【讨论】:

    猜你喜欢
    • 2019-08-15
    • 1970-01-01
    • 2016-08-04
    • 2019-05-07
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多