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
Error
Code
How do I fix the XHR error? Technically, this is not error, it is normal response. The message tells you that you just tried to enter a secure room without the key, your error is that you don't have the key/authorization to enter that room. The only solution is to get the key/credentials and include on the request.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With