Rails:提供令牌时 InvalidAuthenticityToken

发布于 2024-09-28 01:31:00 字数 939 浏览 3 评论 0原文

我正在尝试使用 Java Applet 将文件上传到我的 Rails 应用程序。但是我不断收到以下错误,但我不明白为什么:

处理类别控制器#upload_image(适用于 127.0.0.1,2010-10-18 20:32:54)[POST] 参数:{“partitionIndex”=>“0”,“fileId”=>“8278320”,“lastModified”=>“2010-09-18T14:31:12.610-0500”,“fileLength”=>” 18571", "fileName"=>"dreamstime_1038438.jpg.zip", "partitionCount"=>"1", "authenticity_token"=>"NHX938BYOQr/B4t1pb4pTMlgEFumfveXGxtROSChJpk=", "file"=>#}

ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken): :10:在同步' C:/Ruby/lib/ruby/1.9.1/webrick/httpserver.rb:111:in服务' C:/Ruby/lib/ruby/1.9.1/webrick/httpserver.rb:70:in run' C:/Ruby/lib/ruby/1.9.1/webrick/server.rb:183:instart_thread 中的块

我包含了参数authenticity_token,如上面所示。 authenticity_token 参数由 form_authenticity_token() 生成。在同一页面中有一个表单,并且authenticity_token是完全相同的。我在这里忽略了什么想法吗?

I'm trying to use an Java Applet for uploading files to my rails application. However I keep getting the following error and I can't figure out why:

Processing CategoriesController#upload_image (for 127.0.0.1 at 2010-10-18 20:32:54) [POST]
Parameters: {"partitionIndex"=>"0", "fileId"=>"8278320", "lastModified"=>"2010-09-18T14:31:12.610-0500", "fileLength"=>"18571", "fileName"=>"dreamstime_1038438.jpg.zip", "partitionCount"=>"1", "authenticity_token"=>"NHX938BYOQr/B4t1pb4pTMlgEFumfveXGxtROSChJpk=", "file"=>#}

ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken):
:10:in synchronize'
C:/Ruby/lib/ruby/1.9.1/webrick/httpserver.rb:111:in
service'
C:/Ruby/lib/ruby/1.9.1/webrick/httpserver.rb:70:in run'
C:/Ruby/lib/ruby/1.9.1/webrick/server.rb:183:in
block in start_thread'

I included the parameter authenticity_token as you can see above. The authenticity_token parameter is generated by form_authenticity_token(). In the same page there is a form and the authenticity_token is exactly the same. Any ideas what I'm overlooking here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纸短情长 2024-10-05 01:31:00

Authenticity token is used to prevent CSRF attacks (more info here: Understanding the Rails Authenticity Token).
Maybe your applet is not maintaing its session? and each request is being sent as a separate session? This would cause the error you're facing to happen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文