Reputation: 61
Future<void> _getShopListAllJson() async {
try {
final response = await http.get("http://abair.gq/db_dept_info_all.php");
if (response.statusCode == 200) {
print(response.statusCode);
print(response.body);
setState(() {
_data = jsonDecode(response.body) as List;
});
} else {
print("Some error: ${response.statusCode}");
}
} catch (e) {
print(e);
}
}
Please see above code flutter web api calling error xmlhttprequest
Upvotes: 6
Views: 6349
Reputation: 1248
Looks like CORS is blocking it, try adding a CORS proxy in front of your URL.
Add this in front of your URL https://cors-anywhere.herokuapp.com/
final response = await http.get("https://cors-anywhere.herokuapp.com/http://abair.gq/db_dept_info_all.php");
Once you can confirm it is working it is best practice to have your own proxy so create one using this method:
https://github.com/Rob--W/cors-anywhere/#documentation
Upvotes: 17