Laravel 5 + AngularJS Cross Domain CORS

后端 未结 7 1525
暖寄归人
暖寄归人 2020-12-31 23:28

I have searched everywhere for an answer but nothing have worked so far. All the listed solutions on stack have not proven to be sufficient.

I get nothing in my lar

7条回答
  •  伪装坚强ぢ
    2020-12-31 23:52

    I don't have good knowledge in laravel.but My suggestion is to the request headers to access REST Methods(GET,POST,PUT,DELTE) and origin to specific domain from which domain your making request in the following way or else set to '*'(it allows any domain)

    header('Access-Control-Allow-Origin', 'some url');
    header('Allow', 'GET, POST, OPTIONS');
    header('Access-Control-Allow-Headers', 'Origin, Content-Type, Accept, Authorization, X-Request-With');
    header('Access-Control-Allow-Credentials', 'true');
    

    At angular js.If you use <1.2 you can set CORS in controller file like following way.In latest version not required it will set default.you need to set what content type your expecting from server default is json.If your expecting other type of content you can set manually in the request.

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

提交回复
热议问题