获取HTTP重定向的地址列表

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

获取HTTP重定向的地址列表

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'.
  });
}

Copyright© 2013-2019

京ICP备2023019179号-2