xmlhttprequest error flutter
this worked for me, I added the below header on the lambda function
return {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "*", // Required for CORS support to work
"Access-Control-Allow-Credentials": true, // Required for cookies, authorization headers with HTTPS
"Access-Control-Allow-Headers": "Origin,Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,locale",
"Access-Control-Allow-Methods": "POST, OPTIONS"
},
body: JSON.stringify(item)
};
4
2
[Solved] IN Flutter Web getting ‘XMLHttpRequest’ error while making HTTP call
Thank you!
2
0
0
0
// Get your local IP by ipconfig (command prompt)
// XAMPP Apache 2.4 httpd.conf:
<Directory />
Require local
Require ip 192.168.0
</Directory>
// Flutter side: add headers to async method:
var response = await http.get(Uri.parse("http://192.168.0.54/api.php"),
headers: {
"Accept": "application/json",
"Access-Control-Allow-Origin": "*"
});
// php side (api.php):
<?php // Modify header too
header('Content-Type: application/json');
header("Access-Control-Allow-Origin: *"); // CORS
header("Access-Control-Allow-Headers: Access-Control-Allow-Origin, Accept");
echo json_encode(['id' => '33', 'success' => 'OK']);
?>
Thank you!
0
0
Are there any code examples left?
New code examples in category Dart
-
Dart 2022-03-27 22:05:31 how to create a toast in flutter
-
Dart 2022-03-27 21:10:09 dart string empty or null
-
Dart 2022-03-27 16:20:02 golang radom array
-
Dart 2022-03-25 08:00:34 flutter outline button overlay
-
Dart 2022-03-24 23:50:20 sort list dart
-
Dart 2022-03-24 21:00:01 how to obfuscate flutter code
-
Dart 2022-03-22 13:45:18 box decoration s flutter
-
Dart 2022-03-22 07:20:04 New Year's Eve
-
Dart 2022-03-17 17:10:05 string to int in dart
-
Dart 2022-03-17 12:40:14 dart how to tell if an object is an instance of a class