downloadText function

Future<String> downloadText(
  1. Uri uri, {
  2. void headers(
    1. HttpHeaders
    ) = _plainTextHeader,
  3. void cookies(
    1. List<Cookie>
    )?,
  4. bool isSuccessfulStatusCode(
    1. int
    ) = _isSuccessfulStatusCode,
  5. SecurityContext? context,
  6. Duration connectionTimeout = const Duration(seconds: 10),
  7. Encoding encoding = utf8,
})

Download plain text from the given Uri.

It is possible to configure HttpHeaders and Cookies sent to the server by providing the functions headers and cookies, respectively.

By default, the Accept header is set to text/plain.

A response is considered successful if the isSuccessfulStatusCode function returns true. If it is not, an HttpCodeException is thrown. By default, defaultSuccessfulStatusCodes is used.

A connectionTimeout and an Encoding (UTF-8 by default) may be provided.

This method opens a single connection to make a GET request, and closes that connection before returning, so it is not suitable for making several requests to the same server efficiently.

Implementation

Future<String> downloadText(Uri uri,
    {void Function(HttpHeaders) headers = _plainTextHeader,
    void Function(List<Cookie>)? cookies,
    bool Function(int) isSuccessfulStatusCode = _isSuccessfulStatusCode,
    SecurityContext? context,
    Duration connectionTimeout = const Duration(seconds: 10),
    Encoding encoding = utf8}) async {
  return download(uri,
          headers: headers,
          cookies: cookies,
          context: context,
          connectionTimeout: connectionTimeout,
          isSuccessfulStatusCode: isSuccessfulStatusCode)
      .transform(encoding.decoder)
      .join();
}