postHttpForDevice<T> static method
void
postHttpForDevice<T>(})
Implementation
static void postHttpForDevice<T>(
String url, {
required Map<String, dynamic> parameters,
Function(Map response)? onSuccess,
Function(String error)? onError,
}) async {
Map<String, dynamic> param = {
'Accept': '*/*',
'Content-Type': 'application/json; charset=utf-8',
};
//更新header参数配置
UnitsForNetwork.dio?.options.headers = param;
try {
Response response;
Dio? dio = UnitsForNetwork.dio;
response = await dio!.post(url, data: parameters);
var responseData = response.data;
if (responseData != null) {
if (onSuccess != null) onSuccess(responseData);
} else {
if (onError != null) onError(responseData["message"]);
}
debugPrint(responseData.toString());
} catch (e) {
debugPrint('请求出错:$e');
if (onError != null) onError(e.toString());
}
}