postJson method

Future<Map<String, dynamic>> postJson(
  1. RequestParams requestParams
)

这是一个post json 请求

Implementation

Future<Map<String, dynamic>> postJson(RequestParams requestParams) async {
  Response? response;
  Map<String, dynamic> responseMap = HashMap();
  if (requestParams.baseUrl.isNotEmpty) {
    _dio?.options.baseUrl = requestParams.baseUrl;
  }
  try {
    response = await _dio?.post(requestParams.queryUrl,
        data: requestParams.params,
        options: Options(
          headers: requestParams.headers,
        ));
    if (response?.statusCode == 200) {
      if (response?.data is Map) {
        responseMap = response?.data;
      } else {
        responseMap = jsonDecode(response?.data);
      }
      return responseMap;
    } else {
      responseMap["statusMessage"] = response?.statusMessage;
      return responseMap;
    }
  } on DioError catch (e) {
    NetException netException = NetException.create(e);
    return {"errorCode": netException.code, "errorMsg": netException.message};
  } catch (e) {
    return {"errorCode": -1, "errorMsg": "未知异常"};
  }
}