相关疑难解决方法(0)

Flutter:为 Http GET 请求发送 JSON 正文

我需要从我的 Flutter 应用程序向 API 发出 GET 请求,该请求需要请求正文为 JSON(原始)。

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

在此处输入图片说明

现在在我的 Flutter 应用程序中,我正在尝试做同样的事情:

_fetchDoctorAvailability() async {
    var params = {
      "doctor_id": "DOC000506",
      "date_range": "25/03/2019-25/03/2019" ,
      "clinic_id":"LAD000404"
    };

    Uri uri = Uri.parse("http://theapiiamcalling:8000");
    uri.replace(queryParameters: params);

    var response = await http.get(uri, headers: {
      "Authorization": Constants.APPOINTMENT_TEST_AUTHORIZATION_KEY,
      HttpHeaders.contentTypeHeader: "application/json",
      "callMethod" : "DOCTOR_AVAILABILITY"
    });

    print('---- status code: ${response.statusCode}');
    var jsonData = json.decode(response.body);

    print('---- slot: ${jsonData}');
}
Run Code Online (Sandbox Code Playgroud)

但是 API 给了我一个错误说

{message: Missing input json., status: false}

如何在 Flutter 中为 Http GET 请求发送原始(或者更确切地说是 JSON)请求正文?

json dart flutter

13
推荐指数
3
解决办法
2万
查看次数

标签 统计

dart ×1

flutter ×1

json ×1