post method
Sends an HTTP POST request with the given headers
and body
to the given url
.
Implementation
Future<http.Response> post(
String url, {
Map<String, String>? headers,
Object? body,
Encoding? encoding,
}) async {
// calling the http POST method using the retry approach
final http.Response response = await retry(
() => client
.post(
Uri.parse(Uri.encodeFull(url)),
headers: headers,
body: body,
encoding: encoding,
)
.timeout(const Duration(seconds: 20)),
delayFactor: const Duration(seconds: 5),
maxAttempts: 15,
retryIf: (e) => e is SocketException || e is TimeoutException,
onRetry: (e) => print('${e.runtimeType} - Retrying to POST $url'),
);
return response;
}