简体   繁体   中英

Flutter - XMLHttpRequest has been bloked by CORS policy

I'm working on Flutter and in my php API, I put these headers :

header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET');
header("Access-Control-Allow-Headers: X-Requested-With");

but I still have the anserw :

" Access to XMLHttpRequest at 'http://localhost/spring_box/api.php' from origin 'http://localhost:52502' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' "

Can you help me to solve my problem please?

Follow below steps

1- Go to flutter\\bin\\cache and remove a file named: flutter_tools.stamp

2- Go to flutter\\packages\\flutter_tools\\lib\\src\\web and open the file chrome.dart in Text editor.

3- Search & find '--disable-extensions'

4- Add '--disable-web-security'

5- Save. and Try Now

Happy Coding.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM