doPut static method
Implementation
static Future<FastHttpResponse> doPut({
required String url,
body,
Map<String, dynamic> headers = const {},
bool isReconnectStrategyStart = false,
int reconnectTime = 0,
String? hud,
}) async {
adio.BaseOptions options = adio.BaseOptions(
connectTimeout: CONNECT_TIMEOUT,
receiveTimeout: RECEIVE_TIMEOUT,
headers: headers,
contentType: headers.isNotEmpty ? headers['Content-Type'] : "",
);
FormData? formData;
print('request body => ${jsonEncode(body)}');
if (headers.isNotEmpty &&
headers['Content-Type'] == "application/formData") {
formData = FormData.fromMap(body);
}
Map result = {};
adio.Dio dio = fastDio ?? adio.Dio(options);
late FastHttpResponse httpResponse;
//如果要提示加载中之类的hud
if (hud != null && hud.isNotEmpty) {
EasyLoading.show(status: hud);
}
adio.Response response = await dio
.put(
url,
data: formData ?? body,
)
.catchError((e) async {
DioError error = e;
print('catchError => ${error.message}');
if (reconnectTime > 0 &&
isReconnectStrategyStart &&
(error.type == DioErrorType.sendTimeout ||
error.type == DioErrorType.receiveTimeout ||
error.type == DioErrorType.connectTimeout)) {
print('start reconnect reconnectTime left: $reconnectTime');
httpResponse = await doPost(
url: url,
body: body,
headers: headers,
isReconnectStrategyStart: isReconnectStrategyStart,
reconnectTime: reconnectTime--,
);
// ignore: invalid_return_type_for_catch_error
return httpResponse;
} else {
result = {
"msg": "Server busy,please try again later",
"code": -1,
"msgCode": "1"
};
httpResponse = FastHttpResponse(jsonEncode(result), -1, {}, result);
// ignore: invalid_return_type_for_catch_error
return httpResponse;
}
});
if (hud != null && hud.isNotEmpty) {
EasyLoading.dismiss();
}
if (response.statusCode == HttpStatus.ok) {
var data = response.data;
if (data is String) {
result = jsonDecode(data);
} else if (data is Map) {
result = data;
}
} else {
print(
"object response?.statusCoderesponse?.statusCoderesponse?.statusCoderesponse?.statusCode");
result = {
"msg": "Server busy",
"code": response.statusCode,
"msgCode": "1"
};
if (fastDio != null) {
throw result; //新版本 兼容旧版本
}
}
httpResponse = FastHttpResponse(
jsonEncode(result), response.statusCode, response.headers.map, result);
return httpResponse;
}