I'm in process of developing one application in which I am making 'http' request using import 'package:http/http.dart' as http;
package. This request is working fine when I use that in Android
and iOS
but in Fultter Web
I am getting CORS Policy
issue.
Code
Future<Details> verification(String id) async {
final http.Response response = await http
.post(
'https://secure.iccrc-crcic.ca/search/do/lang/en',
headers: <String, String>{
'Content-Type': 'application/x-www-form-urlencoded',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST,GET,DELETE,PUT,OPTIONS',
'Accept': '*/*'
},
body:
"form_fields=%20lang%3Den%26search_last_name%3D%26search_first_name%3D%26search_iccrc_number%3D$id%26search_membership_status%3D1%26search_company_name%3D%26search_agent%3D%26search_country%3D%26search_province%3D%26search_postal_code%3D%26search_city%3D%26search_street%3D&query=%20&letter=%20&start=%200",
)
.timeout(Duration(minutes: 1));
if (response.statusCode == 200) {
return verificationEmail(response.body);
} else {
throw Exception('Failed to create album.');
}
}
Error
Access to XMLHttpRequest at 'https://secure.iccrc-crcic.ca/search/do/lang/en'
from origin 'https://immigration-101.web.app' has been blocked by CORS policy:
Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
I don't have any control over endpoints where I am making requests so can't add allow headers solution in an endpoint.
Please help me out.