Flutter-从url_launcher获取HTTP响应

时间:2018-10-23 19:17:45

标签: http dart flutter http-status-codes

在Flutter中,很容易使用url_launcher图A )将用户带到网站。我正在寻找一种在完成/失败后返回HTTP状态代码的方法。理想情况下,将其以字符串形式返回以输出文本。

图A;

_launchURL() async {
  const url = 'https://google.com/';
  if (await canLaunch(url)) {
    await launch(url);
  } else {
    throw 'Could not launch $url';
  }
}

谢谢

1 个答案:

答案 0 :(得分:1)

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

void _loadFromUrl(String url) async {
  http.Response response = await http.get(url);
  if (response.statusCode == 200) {...}
  else {...}

希望对您有帮助