从外部表单接收POST

编程入门 行业动态 更新时间:2024-10-24 17:29:24
本文介绍了从外部表单接收POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在另一个网站(使用不同的后端)上有一个表单,我希望能够发布到我的Rails应用程序(在不同的域中)。

  • 如何为外部表单生成有效的真实性标记,以便我的Rails应用程序可以接受它? - 我还需要做些什么才能做到这一点?除了真实性标记之外,其余部分对我来说似乎很简单......

感谢您的帮助!

解决方案

您无法从Rails应用程序外部生成真实标记。 您可以做的是禁用令牌保护功能 a>仅用于此操作,并使用基于before_filter的自定义实现。

skip_before_filter:verify_authenticity_token,:only => :my_action before_filter:verify_custom_authenticity_token,:only => :my_action $ b def verify_custom_authenticity_token #检查请求是否来自信任源结束

I have a form on another website (using a different backend) that I want to be able to POST to my Rails application (on a different domain).

  • How do I generate a valid authenticity token for the external form so that my Rails app will accept it?
  • Assuming I can do the answer to the above question--is there anything else special I need to do to make this work? Apart from the authenticity token, the rest of it seems pretty straightforward to me...

Thanks for the help!

解决方案

You can't generate an autenticity token from outside your Rails app. What you can do, is to disable the token protection only for this action and use a custom implementation based on a before_filter.

skip_before_filter :verify_authenticity_token, :only => :my_action before_filter :verify_custom_authenticity_token, :only => :my_action def verify_custom_authenticity_token # checks whether the request comes from a trusted source end

更多推荐

从外部表单接收POST

本文发布于:2023-10-09 18:37:10,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   POST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!