【发布时间】:2019-08-15 08:08:16
【问题描述】:
我需要从我的 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}');
}
但是 API 给了我一个错误提示
{message: Missing input json., status: false}
如何在 Flutter 中为 Http GET 请求发送原始(或者更确切地说是 JSON)请求正文?
【问题讨论】: