重定向在轨道上为预检角给予响应是无效的错误
问题描述:
我有前端的应用程序中的角4和导轨后端5.重定向在轨道上为预检角给予响应是无效的错误
我已经集成在我的应用程序的支付服务,这将成功响应发布回给定的url。由于响应是后格式,因此我无法在angular上处理它。因此,我将后端的url作为重定向url。
现在我想重定向到前端(角)提供支付服务的响应。
在使用Rails redirect_to的方法,它给我的错误:
Response for preflight is invalid
但有时候错误是
Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.
如何解决这个问题?
答
请参阅以下文档,并遵循如何避免提前发送请求。如果飞行前请求是必须的,则需要使用正确的方法,来源和标头在服务器中进行修复。
当发送预检请求时,将在以下文档中明确记录。
https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
In particular, a request is preflighted if any of the following conditions is true:
If the request uses any of the following methods:
PUT
DELETE
CONNECT
OPTIONS
TRACE
PATCH
Or if, apart from the headers set automatically by the user agent (for example, Connection, User-Agent, or any of the other header with a name defined in the Fetch spec as a “forbidden header name”), the request includes any headers other than those which the Fetch spec defines as being a “CORS-safelisted request-header”, which are the following:
Accept
Accept-Language
Content-Language
Content-Type (but note the additional requirements below)
Last-Event-ID
DPR
Downlink
Save-Data
Viewport-Width
Width
Or if the Content-Type header has a value other than the following:
application/x-www-form-urlencoded
multipart/form-data
text/plain
Or if one or more event listeners are registered on an XMLHttpRequestUpload object used in the request.
Or if a ReadableStream object is used in the request.