handling CORS preflight request in Apache

前端 未结 3 1195
走了就别回头了
走了就别回头了 2021-01-02 19:29

I have a AngularJS app deployed using Yeoman. Cakephp RESTful backend.

The Angular app sends in OPTIONS preflight requests, which the backend responds with forbidden

3条回答
  •  青春惊慌失措
    2021-01-02 19:58

    Add this to your .htaccess file to your apache root directory:

    Header add Access-Control-Allow-Origin "*"
    Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
    Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
    

    Make sure to activate the apache module headers:

    a2enmod headers
    

    Source: https://stackoverflow.com/a/11691776/1494875

提交回复
热议问题