Pre-Flight 正在发送 Http 'OPTIONS' 方法而不是 'DELETE'
Pre-Flight Http 'OPTIONS' Method being sent instead of 'DELETE'
我已经在这个问题上停留了几个小时,但没有运气,所以我想我会在这里问一下。
我有一个带有一堆端点的服务,其中大部分接受 GET
和 POST
http 方法。在那种情况下,我的服务只是在响应 headers 中将 Access-Control-Allow-Origin
指定为 *
,以防我的一个应用程序在不同的 domain/port 上并且想要使用服务。
我有 一个 使用 DELETE
http 方法的端点,但我似乎无法让它工作。当我从我的客户端应用程序调用此端点时,我在我的控制台中收到此消息:
Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
过去几个小时我一直在研究 CORS,并尝试了一些不同的方法,但都没有奏效。我(想我)至少明白,当我使用 GET
和 POST
以外的 http 方法时,浏览器会发送一个 pre-flighted 请求,其中 OPTIONS
作为 http 方法.
处理此问题的最佳方法是什么?有没有办法禁用此 pre-flighted 请求?我在我的客户端应用程序中指定调用此端点的 http 方法是 DELETE
。我是否应该在调用此端点的 AJAX 函数中放置指定 headers 的内容(我直接使用 JavaScript)?
如果我找不到解决这个问题的方法,我将更改我的端点以使用 GET
或 POST
方法,但我想找到一种方法来在我采取简单的方法之前解决这个问题。
I (think I) at least understand that when I'm using http methods other than GET
and POST
, the browser sends a pre-flighted request with OPTIONS
as the http method.
是
Is there a way to disable this pre-flighted request?
不,没有。它由浏览器自动启动,无法从您的 JS 中禁用它。只要您在 JS 中发送 DELETE
请求 cross-origin,浏览器就会进行预检。
Should I be putting something specifying headers in my AJAX function that calls this endpoint?
鉴于“No 'Access-Control-Allow-Origin' header is present on the requested resource”消息,您没有对客户端代码进行任何更改会有什么不同。
需要发送更多 header 来处理这个问题的地方是在服务器端。
If I can't figure out a way around this, I'm just going to change my endpoint to use a GET
or POST
method
您可能想先尝试一下。似乎即使您进行了更改,您仍然会得到“请求的资源 上没有 'Access-Control-Allow-Origin' header”。
SO 问题 "No 'Access-Control-Allow-Origin' header is present on the requested resource" 是阅读此问题以更好地了解正在发生的事情的好地方。
我已经在这个问题上停留了几个小时,但没有运气,所以我想我会在这里问一下。
我有一个带有一堆端点的服务,其中大部分接受 GET
和 POST
http 方法。在那种情况下,我的服务只是在响应 headers 中将 Access-Control-Allow-Origin
指定为 *
,以防我的一个应用程序在不同的 domain/port 上并且想要使用服务。
我有 一个 使用 DELETE
http 方法的端点,但我似乎无法让它工作。当我从我的客户端应用程序调用此端点时,我在我的控制台中收到此消息:
Response to preflight request doesn't pass access control check:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
过去几个小时我一直在研究 CORS,并尝试了一些不同的方法,但都没有奏效。我(想我)至少明白,当我使用 GET
和 POST
以外的 http 方法时,浏览器会发送一个 pre-flighted 请求,其中 OPTIONS
作为 http 方法.
处理此问题的最佳方法是什么?有没有办法禁用此 pre-flighted 请求?我在我的客户端应用程序中指定调用此端点的 http 方法是 DELETE
。我是否应该在调用此端点的 AJAX 函数中放置指定 headers 的内容(我直接使用 JavaScript)?
如果我找不到解决这个问题的方法,我将更改我的端点以使用 GET
或 POST
方法,但我想找到一种方法来在我采取简单的方法之前解决这个问题。
I (think I) at least understand that when I'm using http methods other than
GET
andPOST
, the browser sends a pre-flighted request withOPTIONS
as the http method.
是
Is there a way to disable this pre-flighted request?
不,没有。它由浏览器自动启动,无法从您的 JS 中禁用它。只要您在 JS 中发送 DELETE
请求 cross-origin,浏览器就会进行预检。
Should I be putting something specifying headers in my AJAX function that calls this endpoint?
鉴于“No 'Access-Control-Allow-Origin' header is present on the requested resource”消息,您没有对客户端代码进行任何更改会有什么不同。
需要发送更多 header 来处理这个问题的地方是在服务器端。
If I can't figure out a way around this, I'm just going to change my endpoint to use a
GET
orPOST
method
您可能想先尝试一下。似乎即使您进行了更改,您仍然会得到“请求的资源 上没有 'Access-Control-Allow-Origin' header”。
SO 问题 "No 'Access-Control-Allow-Origin' header is present on the requested resource" 是阅读此问题以更好地了解正在发生的事情的好地方。