Reputation: 5107
I am new creating Flutter web projects, and I have found the first issue when trying to make http connections to files hosted on the same server where the Flutter web build is deployed.
This is the code:
Future<User> obtenerUsuario() async {
setState(() {
isLoading = true;
});
var url = "https://.../login.php";
final response = await http.post(url, body: {
"email": controlUsuario.text,
"password": controlContrasena.text
});
print("respuesta :"+response.body);
And this is the error message from browser console:
Access to XMLHttpRequest at 'https://.../login.php' from origin 'http://...' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
The project is hosted on a AWS Ubuntu instance.
Upvotes: 0
Views: 652
Reputation: 1538
Add the following code to your server .htaccess
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
Upvotes: 1