Rails:ERROR EOFError:POSTING时内容不正确

时间:2015-08-20 17:23:28

标签: ruby-on-rails

尝试POST到API(本地)时出现以下错误。该请求会生成500;身体说bad content body,终端读起来像这样

[2015-08-20 12:12:38] ERROR EOFError: bad content body
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/rack-1.5.5/lib/rack/multipart/parser.rb:83:in `block in fast_forward_to_first_boundary'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/rack-1.5.5/lib/rack/multipart/parser.rb:81:in `loop'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/rack-1.5.5/lib/rack/multipart/parser.rb:81:in `fast_forward_to_first_boundary'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/rack-1.5.5/lib/rack/multipart/parser.rb:17:in `parse'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/rack-1.5.5/lib/rack/multipart.rb:25:in `parse_multipart'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/rack-1.5.5/lib/rack/request.rb:379:in `parse_multipart'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/rack-1.5.5/lib/rack/request.rb:205:in `POST'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/rack-1.5.5/lib/rack/methodoverride.rb:26:in `method_override'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/rack-1.5.5/lib/rack/methodoverride.rb:14:in `call'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/rack-1.5.5/lib/rack/runtime.rb:17:in `call'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/activesupport-4.1.12/lib/active_support/cache/strategy/local_cache_middleware.rb:26:in `call'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/rack-1.5.5/lib/rack/lock.rb:17:in `call'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/actionpack-4.1.12/lib/action_dispatch/middleware/static.rb:84:in `call'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/rack-1.5.5/lib/rack/sendfile.rb:112:in `call'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/airbrake-4.1.0/lib/airbrake/user_informer.rb:16:in `_call'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/airbrake-4.1.0/lib/airbrake/user_informer.rb:12:in `call'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/railties-4.1.12/lib/rails/engine.rb:514:in `call'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/railties-4.1.12/lib/rails/application.rb:144:in `call'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/railties-4.1.12/lib/rails/railtie.rb:194:in `public_send'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/railties-4.1.12/lib/rails/railtie.rb:194:in `method_missing'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/rack-1.5.5/lib/rack/urlmap.rb:65:in `block in call'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/rack-1.5.5/lib/rack/urlmap.rb:50:in `each'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/rack-1.5.5/lib/rack/urlmap.rb:50:in `call'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/rack-1.5.5/lib/rack/deflater.rb:25:in `call'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/rack-1.5.5/lib/rack/lock.rb:17:in `call'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/rack-1.5.5/lib/rack/content_length.rb:14:in `call'
        /Users/akdemia15/.rvm/gems/ruby-2.2.2/gems/rack-1.5.5/lib/rack/handler/webrick.rb:60:in `service'
        /Users/akdemia15/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
        /Users/akdemia15/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
        /Users/akdemia15/.rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'

我没有向请求发送任何类型的参数。为什么会发生错误?使用GET时不会发生这种情况。我正在使用Rails 4.1.12和Ruby 2.2.2

1 个答案:

答案 0 :(得分:4)

我尝试了curl上的请求(我之前使用的是Postman)并且它有效。当我在form-data标签中选择了BODY但没有放置实际数据(它是空的)时,我发现Postman很麻烦。将选项更改为raw并将其留空也适用于我