在 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';
}
}
谢谢
最佳答案
import 'package:http/http.dart' as http;
void _loadFromUrl(String url) async {
http.Response response = await http.get(url);
if (response.statusCode == 200) {...}
else {...}
希望对你有帮助
关于http - Flutter - 从 url_launcher 获取 HTTP 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52956398/