post method
发送请求,携带 accessToken
Implementation
Future<CloudBaseResponse> post(
String action, Map<String, dynamic> data) async {
data.addAll({
'action': action,
'env': _core.config.envId,
'sdk_version': _VERSION,
'dataVersion': _DATA_VERSION,
});
if (_core.auth != null) {
// 获取 accesstoken
String accessToken = await _core.auth!.getAccessToken();
data.addAll({'access_token': accessToken});
}
data = await Sign.signData(_core, data);
final Response response = await _tracePost(_TCB_WEB_URL, data);
if (response.data['code'] == 'ACCESS_TOKEN_EXPIRED') {
await _core.auth!.refreshAccessToken();
return await this.post(action, data);
}
// 从 HTTP 响应 data 中解析数据
return CloudBaseResponse.fromMap(response.data);
}