postRequest static method
Http post request
Implementation
static postRequest({required Uri url, Map<String, String>? headers, required dynamic body}) async {
try {
UnifiedRequest prepared = await UnifiedInterceptorRunner.runOnRequest(
UnifiedRequest(method: 'POST', uri: url, headers: headers, body: body),
_interceptors,
);
debugPrint('requesting post : ${prepared.uri}');
final response = _client != null
? await _client!.post(prepared.uri, headers: prepared.headers, body: json.encode(prepared.body))
: await http.post(prepared.uri, headers: prepared.headers, body: json.encode(prepared.body));
await UnifiedInterceptorRunner.runOnResponse(
UnifiedResponse(
statusCode: response.statusCode,
data: response.body,
headers: response.headers,
request: prepared,
),
_interceptors,
);
return response;
} on PlatformException catch (e, st) {
await _notifyError(e, st, request: UnifiedRequest(method: 'POST', uri: url, headers: headers, body: body));
return Failure(UnifiedHttpClientEnum.platformExceptionError, 'Platform Exception Caught : $e');
} on SocketException catch (e, st) {
await _notifyError(e, st, request: UnifiedRequest(method: 'POST', uri: url, headers: headers, body: body));
return Failure(UnifiedHttpClientEnum.socketExceptionError, 'Socket Exception:$e');
} on FormatException catch (e, st) {
await _notifyError(e, st, request: UnifiedRequest(method: 'POST', uri: url, headers: headers, body: body));
return Failure(UnifiedHttpClientEnum.formatExceptionError, 'format exception : $e');
} catch (e, st) {
await _notifyError(e, st, request: UnifiedRequest(method: 'POST', uri: url, headers: headers, body: body));
return Failure(UnifiedHttpClientEnum.undefined, 'something went Wrong : $e');
}
}