获取HTTP返回的二进制

1837次阅读  |  发布于5年以前

获取HTTP返回的二进制

Use the bodyBytes field on the Response object to get the response in bytes.

import 'package:http/http.dart' as http;
import 'package:crypto/crypto.dart';

main() async {
  var url = "https://www.dartlang.org/logos/dart-logo.png";
  var response = await http.get(url);
  List<int> bytes = response.bodyBytes;
  // Do something with the bytes. For example, convert to base64.
  String base64 = CryptoUtils.bytesToBase64(bytes);
  print(base64);
}

Copyright© 2013-2019

京ICP备2023019179号-2