An HTTP request may return a response, or it may generate an error.
import 'package:http/http.dart' as http;
handleSuccess(http.Response response) {
print('something went right!');
print(response.body);
}
handleFailure(error) {
print('Something went wrong.');
print(error.message);
}
main() async {
try {
var response = await http.get("http://some_bogus_website.org");
handleSuccess(response);
} catch (e) {
handleFailure(e);
}
}
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8