post static method

Future<Response> post(
  1. Uri url, {
  2. Map<String, String>? headers,
  3. Object? body,
  4. Encoding? encoding,
  5. Duration? timeout,
})

Implementation

static Future<Response> post(Uri url,
    {Map<String, String>? headers,
    Object? body,
    Encoding? encoding,
    Duration? timeout}) async {
  var newHeader = _defaultHeaders(headers);
  final effectiveTimeout = timeout ?? requestTimeout;
  var client = http.Client();
  try {
    return await client
        .post(url,
            body: jsonEncode(body), encoding: encoding, headers: newHeader)
        .timeout(effectiveTimeout, onTimeout: () {
      client.close();
      throw TimeoutException("POST request timed out.", effectiveTimeout);
    });
  } finally {
    client.close();
  }
}