【问题标题】:Redirect from ruby on rails to angular giving Response for preflight is invalid error从 ruby​​ on rails 重定向到 angular 给 preflight 的响应是无效错误
【发布时间】:2018-03-15 13:33:51
【问题描述】:

我有一个前端在 angular 4 中,后端在 rails 5 中的应用程序。

我已在我的应用程序中集成了一项支付服务,该服务将成功响应发布回给定的 URL。由于响应是 post 格式,所以我无法在 angular 上处理它。所以我将后端的 url 作为重定向 url。

现在我想重定向到提供支付服务响应的前端(角度)。

在使用 rails redirect_to 方法时,它给了我一个错误:

预检响应无效

但有时错误是

预检响应中的 Access-Control-Allow-Headers 不允许请求标头字段授权。

如何解决这个问题?

【问题讨论】:

    标签: ruby-on-rails angularjs cors


    【解决方案1】:

    请参阅以下文档并了解如何避免飞行前请求。如果飞行前请求是必须的,那么它需要在服务器中使用正确的方法、来源和标头进行修复。

    何时发送预检请求已在以下文档中明确记录。

    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.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-06
      • 2016-10-20
      • 2016-06-20
      • 1970-01-01
      • 1970-01-01
      • 2015-09-16
      • 2012-02-24
      • 1970-01-01
      相关资源
      最近更新 更多