我需要从我的Flatter应用程序向API发出GET请求,该应用程序要求请求主体为JSON(原始).
我在Postman中用JSON请求体测试了API,它似乎运行良好.
现在,在我的Flutter 翼应用程序中,我也在try 做同样的事情:
_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给我一个错误,说明
{消息:缺少输入json,状态:false}
如何在flatter中为Http GET请求发送原始(或者更确切地说是JSON)请求体?