Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 如何在Dart中获取重定向url?_Flutter_Dart - Fatal编程技术网

Flutter 如何在Dart中获取重定向url?

Flutter 如何在Dart中获取重定向url?,flutter,dart,Flutter,Dart,在我的项目中,我发送了简单的授权请求: http.Response response = await http.get(url, headers: headers); 作为回应,我有cookieID和其他信息,但我没有收到重定向url 我怎样才能带他去?默认情况下,package:http和底层的HttpClient将自动跟随http重定向 如果您不想这样做,则可以通过设置为false来禁用它 package:http通过公开这一点。正如jamesdlin上面提到的,http的重定向默认设置为

在我的项目中,我发送了简单的授权请求:

http.Response response = await http.get(url, headers: headers);
作为回应,我有cookieID和其他信息,但我没有收到重定向url


我怎样才能带他去?

默认情况下,
package:http
和底层的
HttpClient
将自动跟随http重定向

如果您不想这样做,则可以通过设置为
false
来禁用它


package:http
通过公开这一点。

正如jamesdlin上面提到的,http的重定向默认设置为true。为了避免重定向,需要将followRedirects设置为false。可按如下方式获取重定向URI:

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

http.Request req = http.Request("Get", Uri.parse(YOUR_URL_HERE))..followRedirects = false;
http.Client baseClient = http.Client();
http.StreamedResponse response = await baseClient.send(req);
Uri redirectUri = Uri.parse(response.headers['location'])