I'm trying to retrieve a webpage in an Action so I can web scrape the response into my FlutterFlow app.
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/backend/schema/structs/index.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import 'package:http/http.dart' as http;
Future<String> fetchbusinessinfo(String businessNumber) async {
// This function takes a business registration number as input and returns
// the webpage of the corresponding business in Flutter
// Construct the URL for the business' webpage
String url =
'https://www.governmentOrganization.org/' +
businessNumber;
// Use the http package to make a GET request to the URL
var response;
try {
response = await http.get(Uri.parse(url));
} catch (err) {
print('Caught error = $err');
}
// Check if the response was successful
if (response.statusCode == 200) {
// If successful, return the HTML content of the webpage
return response.body;
} else {
// If unsuccessful, throw an error
throw Exception('Failed to load business webpage');
}
}
The code exits with err = "XMLHttpRequest error." after the catch
block.
Any thoughts / suggestions ?