Response to preflight request doesn't pass access control check

后端 未结 21 2195
别那么骄傲
别那么骄傲 2020-11-22 03:50

I\'m getting this error using ngResource to call a REST API on Amazon Web Services:

XMLHttpRequest cannot load http://server.apiurl.com:8000/s/login

21条回答
  •  情歌与酒
    2020-11-22 04:16

    My "API Server" is an PHP Application so to solve this problem I found the below solution to work:

    Place the lines in index.php

    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
    header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
    

提交回复
热议问题