且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用自定义HTTP标头发送跨域请求时禁用预检OPTION请求

更新时间:2021-10-07 05:43:45

不,绝对不可能绕过CORS预检请求。预检请求的存在是为了以安全的方式允许跨域请求。在上面的示例中,您尝试访问google.fr,但google.fr不支持CORS。 Google无法解决此问题,因为Google不支持其网页上的跨域请求。通常,如果您拥有服务器的所有权,那么您的选择是支持CORS,支持JSON-P等替代跨域攻击,或者使用服务器端代理。

No, it is definitely not possible to bypass the CORS preflight request. The preflight request exists to allow cross-domain requests in a safe manner. In your example above, you are trying to access google.fr, but google.fr doesn't support CORS. There is no way around this for Google, since Google doesn't support cross-domain requests on its web page. In general, if you have ownership of the server, your options are to support CORS, support alternative cross-domain hacks like JSON-P, or use a server-side proxy.