dart http xmlhttprequest error code example
Example 1: xmlhttprequest error flutter
this worked for me, I added the below header on the lambda function
return {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": true,
"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)
};
Example 2: XAMPP flutter CORS policy
<Directory />
Require local
Require ip 192.168.0
</Directory>
var response = await http.get(Uri.parse("http://192.168.0.54/api.php"),
headers: {
"Accept": "application/json",
"Access-Control-Allow-Origin": "*"
});
<?php
header('Content-Type: application/json');
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Access-Control-Allow-Origin, Accept");
echo json_encode(['id' => '33', 'success' => 'OK']);
?>