diff --git a/uni/lib/controller/fetchers/departures_fetcher.dart b/uni/lib/controller/fetchers/departures_fetcher.dart index 921c42113..64e2d3585 100644 --- a/uni/lib/controller/fetchers/departures_fetcher.dart +++ b/uni/lib/controller/fetchers/departures_fetcher.dart @@ -1,8 +1,9 @@ import 'dart:convert'; +import 'dart:io'; import 'package:html/dom.dart'; import 'package:html/parser.dart'; -import 'package:http/http.dart' as http; +import 'package:http/io_client.dart' as http; import 'package:uni/controller/networking/network_router.dart'; import 'package:uni/model/entities/bus.dart'; import 'package:uni/model/entities/bus_stop.dart'; @@ -13,12 +14,17 @@ class DeparturesFetcher { final String _stopCode; final BusStopData _stopData; + static final _client = http.IOClient( + HttpClient(context: SecurityContext()) + ..badCertificateCallback = + (cert, host, port) => host == 'www.stcp.pt' && port == 443, + ); Future _getCSRFToken() async { final url = 'https://www.stcp.pt/en/travel/timetables/?paragem=$_stopCode&t=smsbus'; - final response = await http.get(url.toUri()); + final response = await _client.get(url.toUri()); final htmlResponse = parse(response.body); final scriptText = htmlResponse @@ -50,7 +56,7 @@ class DeparturesFetcher { final url = 'https://www.stcp.pt/pt/itinerarium/soapclient.php?codigo=$_stopCode&hash123=$csrfToken'; - final response = await http.get(url.toUri()); + final response = await _client.get(url.toUri()); final htmlResponse = parse(response.body); final tableEntries = @@ -111,7 +117,8 @@ class DeparturesFetcher { // Search by approximate name final url = 'https://www.stcp.pt/pt/itinerarium/callservice.php?action=srchstoplines&stopname=$stopCode'; - final response = await http.post(url.toUri()); + + final response = await _client.post(url.toUri()); final json = jsonDecode(response.body) as List; for (final busKey in json) { final bus = busKey as Map; @@ -134,7 +141,8 @@ class DeparturesFetcher { static Future> getBusesStoppingAt(String stop) async { final url = 'https://www.stcp.pt/pt/itinerarium/callservice.php?action=srchstoplines&stopcode=$stop'; - final response = await http.post(url.toUri()); + + final response = await _client.post(url.toUri()); final json = jsonDecode(response.body) as List;