Preflight OPTIONS request by AngularJS not working with Chrome?

前端 未结 5 937
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-18 14:52

I have developed a simple application using AngularJS hosted here. I am consuming an API I developed myself in Laravel hosted here. When I try to log into the application us

5条回答
  •  抹茶落季
    2021-01-18 15:39

    In first you have to send those Headers (wildcard works incorrect sometimes):

    Access-Control-Allow-Headers: X-Requested-With, content-type
    Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS
    

    In second (and important) remove header from AngularJs service $httpProvider in config:

    myApp.config(['$httpProvider', function($httpProvider) {
            $httpProvider.defaults.useXDomain = true;
            delete $httpProvider.defaults.headers.common['X-Requested-With'];
        }
    ]);
    

提交回复
热议问题