import 'dart:io';import 'package:http/http.dart' as http;
void main() { // Gives expected output var url1 = "https://www.google.com"; var url2 = "https://www.github.com"; // Test https://www.google.com http.get(url1).then((http.Response res) { print("Headers:"); print(res.headers); print(""); print("Body:"); print(res.body); print("\n"); })
// Test https://www.github.com .then((_) => http.get(url2)).then((http.Response res) { print("Headers:"); print(res.headers); print(""); print("Body:"); print(res.body); });}Uncaught Error: RedirectException: Redirect loop detectedUnhandled exception:RedirectException: Redirect loop detected#0 _rootHandleUncaughtError.<anonymous closure>.<anonymous closure> (dart:async/zone.dart:700)#1 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:23)#2 _asyncRunCallback (dart:async/schedule_microtask.dart:32)#3 _asyncRunCallback (dart:async/schedule_microtask.dart:36)#4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:119)--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
import 'dart:io';
void main() { var url1 = "https://www.google.com"; var url2 = "https://api.github.com"; var url3 = "https://pages.github.com"; var url4 = "https://help.github.com"; var url5 = "https://github.com"; var url6 = "https://www.github.com"; // Make request new HttpClient().getUrl(Uri.parse(url6)).then((HttpClientRequest request) { print(request.connectionInfo.remoteAddress); print(request.connectionInfo.remotePort); request.close().then((HttpClientResponse response) { List<int> resBuffer = new List<int>(); var r = response.listen(null); print("Response headers:"); response.headers.forEach((key, val) => print(" $key $val")); r.onData((data) => resBuffer.addAll(data)); r.onDone(() { print("Response body:"); print(" ${new String.fromCharCodes(resBuffer)}"); }); r.onError((e) => print(e)); }); });}InternetAddress('192.30.252.129', IP_V6)443Uncaught Error: RedirectException: Redirect loop detectedUnhandled exception:RedirectException: Redirect loop detected#0 _rootHandleUncaughtError.<anonymous closure>.<anonymous closure> (dart:async/zone.dart:700)#1 _asyncRunCallbackLoop (dart:async/schedule_microtask.dart:23)#2 _asyncRunCallback (dart:async/schedule_microtask.dart:32)#3 _asyncRunCallback (dart:async/schedule_microtask.dart:36)#4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:119)I think we figured this out. It seems that HttpClient in Dart doesn't set the Host HTTP header be default. Recently, we started requiring that header on our side, which caused the difference in behavior you observed.Can you please try adding this line to your program, before you call request.close():This should make urls 5 and 6 work.