0

Hello I'm making an app which use http framework and send my server to get request. I'm using Aqueduct for backend service and it is working when I use POSTMAN to send 'get request' but when I use my app to send get request Aqueduct gives a message on console:

[INFO] aqueduct: OPTIONS /workers 8ms 403 {user-agent : Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/IP_ADRESS Safari/537.36\nconnection : keep-alive\naccept : */*\naccept-language : en-US,en;q=0.9\nsec-fetch-mode : cors\naccept-encoding : gzip, deflate, br\norigin : http://localhost:58095\nhost : localhost:8888\nsec-fetch-site : same-site\naccess-control-request-headers : authorization,companymail,content-type\naccess-control-request-method : GET\nreferer : http://localhost:58095/\n}   

When I use postman to send get request everything is fine and server gives response:

[INFO] aqueduct: GET /workers 92ms 200   

My Postman Headers:

companyMail:deneme1234
Content-Type:application/json
Authorization:Basic ZGVuZW1lMTIzNDpkZW5lbWUxMjM0

My flutter app headers:

final Map<String, String> headers = {"Content-Type": "application/json"};  
String basicAuth = 'Basic ' + base64Encode(utf8.encode('$mail:$password'));
  headers['authorization'] = basicAuth;
  headers['companyMail'] = companyMail;
return headers

My flutter app get request:

   final response = http.get(baseUrl+'workers',headers: await authHeader());
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Onur
  • 318
  • 4
  • 12

1 Answers1

0

Finally I've found the solution :) It is about CorsPolicy. If you want to send special header with request, you must check your server acceptable headers. In Aqueduct you can edit your allowed request headers like that:

CORSPolicy.defaultPolicy.allowedRequestHeaders = ['company-mail','content-type','authorization'];    
Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Onur
  • 318
  • 4
  • 12