I am using flutter-web with .net webapi. To shoot my requests, I have tried Dio and Dart HTTP packages. Neither of the two have worked because of CORS issue. Kindly tell me what am I doing wrong. is there a way to get around this problem ? There is no problem with api when it comes to shoot them from postman .
Sample code
I have added
var cors = new EnableCorsAttribute("", "", "*"); config.EnableCors(); in webapi as well.
Flutter HTTP Requests first of the two is built on dio.
Dio dio= new Dio();
Future postData2(user) async{
debugPrint(user.toString());
dynamic data = {
'phone_number': user['country_code'] + user['phone_number'],
'password':user['password']
};
final String pathUrl = "http://localhost:62435/api/Token/GetToken";
var response = await dio.post(pathUrl, data:data, options: Options(
headers: {
'content-type': 'application/json',
'Access-Control-Allow-Origin':'true'
},
));
return response.data;
}
//Http : dart
Future postData(user) async{
dynamic data = {
'phone_number': user['country_code'] + user['phone_number'],
'password':user['password']
};
final String pathUrl = "http://localhost:62435/api/Token/GetToken";
dynamic response = _http.post(
pathUrl,
body : data,
headers : {
HttpHeaders.contentTypeHeader : 'application/json',
//'Access-Control-Allow-Origin':'true'
}
);
debugPrint( //response.statusCode +
" " + response.data.toString());
}
For dio, at least the checkup request is sent

with Dio I get following errors.
Dio Request headers in network tab. The request remains pending. and does not finish.
Request URL: http://localhost:62435/api/Token/GetToken
Referrer Policy: no-referrer-when-downgrade
Provisional headers are shown
Access-Control-Allow-Origin: true
content-type: application/json; charset=utf-8
Referer: http://localhost:63440/
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36
{phone_number: "123124", password: "safaSF"}

