gpt4 book ai didi

ruby-on-rails - 如何处理 protect_from_forgery 以使 Rails 应用程序进行通信?

转载 作者:行者123 更新时间:2023-12-03 08:37:58 25 4
gpt4 key购买 nike

我有一个 Rails 应用程序,它会将一些数据发布到另一个 Rails 应用程序。由于某些原因我不想使用 ActiveResource,所以我使用了类似的东西:

  res = Net::HTTP.post_form(URI.parse('http://localhost:3030/support_requests/new'),
{'from'=>'somebody', 'due'=>'2009-03-31'})

碰巧另一个应用程序抛出一个 InvalidAuthenticityToken,这是有道理的,因为我没有发送任何 authenticity_token。

我的问题是,如何让一个应用向另一个应用发送正确的身份验证 token ?

最佳答案

您不必使用 ActiveResources。如果您以 xml 格式发送请求,那么它将绕过 protect_from_forgery。

curl -H "Content-Type: text/xml" -d "<support-request><from>...</from></support-request>" -X POST http://localhost:3000/support_requests.xml -i

它应该非常简单。

关于ruby-on-rails - 如何处理 protect_from_forgery 以使 Rails 应用程序进行通信?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/269487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com