获取HTTP重定向的地址列表

Android社区 收藏文章

Use the HttpClient class in the 'dart:io' library to make a request, and use the Response redirects property to get a list of the redirects.

import "dart:io" show HttpClient, RedirectInfo;

main() async {
  var client = new HttpClient();
  var request = await client.getUrl(Uri.parse('http://google.com'));
  var response = await request.close();
  List<RedirectInfo> redirects = response.redirects;
  redirects.forEach((redirect) {
    print(redirect.location); // Prints 'http://www.google.com'.
  });
}
相关标签

扫一扫

在手机上阅读