【问题标题】:Rails - How to fake PUT or DELETE request using XDomainRequest in IERails - 如何在 IE 中使用 XDomainRequest 伪造 PUT 或 DELETE 请求
【发布时间】:2011-12-18 00:10:11
【问题描述】:

如何在 IE 中使用 XDomainRequest 伪造 PUT 或 DELETE 请求?还是我需要使用 iframe 传输?

我正在尝试访问为 CORS 设置的 restful API。它适用于所有其他浏览器,但我不知道如何在 IE 中伪造 PUT/DELETE 操作。使用XDomainRequestcustom headers are not allowed,所以我不能添加HTTP_X_HTTP_METHOD_OVERRIDE 标头,它应该告诉Rails 识别json 数据中的_method=put 参数。

【问题讨论】:

    标签: ruby-on-rails internet-explorer xdomainrequest xdr


    【解决方案1】:

    我能想到的最佳解决方案是添加两个映射到#update 和#destroy 的新成员路由:

    resources :posts do
        member do
            post :revise, :action => :update
            post :annihilate, :action => :destroy
        end
    end
    

    当您运行“rake routes”时添加了这些路由:

        revise_post POST   /posts/:id/revise(.:format)     {:action=>"update", :controller=>"posts"}
    annihilate_post POST   /posts/:id/annihilate(.:format) {:action=>"destroy", :controller=>"posts"}
    

    请注意,我最初尝试过这个:

    resources :posts do
        member do
            post :update
            post :destroy
        end
    end
    

    希望它会创建这些路线:

     update_post POST   /posts/:id/update(.:format)  {:action=>"update", :controller=>"posts"}
    destroy_post POST   /posts/:id/destroy(.:format) {:action=>"destroy", :controller=>"posts"}
    

    但它却创造了:

    POST   /posts/:id(.:format) {:action=>"update", :controller=>"posts"}
    POST   /posts/:id(.:format) {:action=>"destroy", :controller=>"posts"}
    

    看起来它们是重叠的,你永远无法到达帖子#destroy。

    【讨论】:

      猜你喜欢
      • 2012-06-28
      • 1970-01-01
      • 2011-01-10
      • 1970-01-01
      • 2013-12-24
      • 2010-11-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多