Rails:提供令牌时 InvalidAuthenticityToken
我正在尝试使用 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:inrun' C:/Ruby/lib/ruby/1.9.1/webrick/server.rb:183:in
start_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:insynchronize'
service'
C:/Ruby/lib/ruby/1.9.1/webrick/httpserver.rb:111:in
C:/Ruby/lib/ruby/1.9.1/webrick/httpserver.rb:70:inrun'
block in start_thread'
C:/Ruby/lib/ruby/1.9.1/webrick/server.rb:183:in
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
真实性令牌用于防止 CSRF 攻击(更多信息请参见:了解 Rails 真实性令牌).
也许您的小程序没有维持其会话?每个请求都作为单独的会话发送?这会导致您面临的错误发生。
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.