readBytes static method
Sends an HTTP GET request with the given headers to the given URL and returns a Future that completes to the body of the response as a list of bytes.
The Future will emit a http.ClientException
if the response doesn't have a success status code.
This automatically initializes a new http.Client
and closes that client once the request is complete. If you're planning on making multiple requests to the same server, you should use a single http.Client
for all of those requests.
指定されたヘッダーを持つ HTTP GET 要求を指定された URL に送信し、バイトのリストとして応答の本文に完了する Future を返します。
レスポンスに成功ステータス コードがない場合、Future は http.ClientException
を発行します。
これにより、新しい http.Client
が自動的に初期化され、リクエストが完了するとそのクライアントが閉じられます。同じサーバーに複数のリクエストを送信する予定がある場合は、それらすべてのリクエストに対して単一の http.Client
を使用する必要があります。
Implementation
static Future<Uint8List> readBytes(
String path, {
Map<String, String>? headers,
}) async {
final url = Uri.parse(path);
return http.readBytes(url, headers: headers);
}