禁止Angular CORS中的OPTIONS请求 [英] Suppress OPTIONS Requests in Angular CORS
问题描述
如果我预见到使用Angular进行的CORS调用确实可以工作,是否可以抑制OPTIONS调用,以免它们在生产中不必要地继续发生?
If I have foreknowledge that CORS calls made with Angular will, indeed, work, can I suppress the OPTIONS calls so that they don't continue needlessly occurring in production?
推荐答案
此OPTIONS请求告诉客户端是否允许CORS请求;对于这些请求,可以执行哪些方法(GET,POST,PUT等).
This OPTIONS request tells the client if a CORS request will be allowed; and, for those requests, which methods (GET, POST, PUT, etc.) can be executed.
According to W3c options call is not required if you are implementing only simple methods: GET/POST/HEAD.
因此,如果您要设置Access-Control-Allow-Methods,请尝试*将其更改为"GET,POST"并根据标准(如果遵循浏览器),则浏览器无需触发选项打电话.
So where you set your Access-Control-Allow-Methods if it is * try changing it to "GET,POST" and based on the standard (if the browser follows), your browser doesn't need to fire the options call.
这篇关于禁止Angular CORS中的OPTIONS请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!