laravel 在 CORS 中真的需要 Angular $http.defaults.useXDomain 吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23147196/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 09:22:49  来源:igfitidea点击:

Is it Angular $http.defaults.useXDomain really neccessary in CORS?

angularjslaravelcors

提问by under5hell

I saw someone using $http.defaults.useXDomain = true in angular when dealing with CORS. Is it really necessary to do that?

我看到有人在处理 CORS 时在 angular 中使用 $http.defaults.useXDomain = true 。真的有必要这样做吗?

I just set up laravel and angular in different domain ( By different domain, I mean I put angular and laravel in completely separated folder in localhost www folder. FYI i use nginx). i hit the laravel controller with http request from angular. It just work fine, Whether i use the $http.defaults.useXDomain or not.

我只是在不同的域中设置了 laravel 和 angular(通过不同的域,我的意思是我将 angular 和 laravel 放在 localhost www 文件夹中完全分离的文件夹中。仅供参考,我使用 nginx)。我用来自angular的http请求点击了laravel控制器。无论我是否使用 $http.defaults.useXDomain,它都能正常工作。

Luckily, this condition make my work little bit easier. but i still wondering is there any explanation why this happened?

幸运的是,这种情况使我的工作更容易一些。但我仍然想知道为什么会发生这种情况有什么解释吗?

回答by J.Wells

No, it's not necessary. In fact, it's not a thing.

不,这是没有必要的。事实上,这不是一回事。

check it out

一探究竟

Cors works via proper headers/preflight requests and responses, which you can do myriad of different ways in angularjs.

Cors 通过正确的标头/预检请求和响应工作,您可以在 angularjs 中以多种不同的方式进行。

Hereis more about cors workings.

是有关 cors 工作原理的更多信息。