sinatra undefined方法'倒带'

时间:2011-07-04 09:46:03

标签: android ruby sinatra

我正试图在我的计算机上将我的Android应用程序中的一些数据发布到Sinatra。 Sinatra听:

post '/upload' do
    puts "*****************************************"
    puts "!!!!!!!! #{params.inspect}"
end

失败了:

ERROR NoMethodError: undefined method `rewind' for "ho":String
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/utils.rb:576:in`block in parse_multipart'
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/utils.rb:499:in`loop'
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/utils.rb:499:in`parse_multipart'
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/request.rb:270:in `parse_multipart'
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/request.rb:148:in `POST'
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/methodoverride.rb:15:in `call'
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1272:in `block in call'
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1303:in `synchronize'
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1272:in `call'
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/content_length.rb:13:in `call'
        D:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/handler/webrick.rb:52:in `service'
        D:/Ruby192/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
        D:/Ruby192/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
        D:/Ruby192/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'

邮政参数是{"hey" => "ho"}。我在rack / utils.rb中打印出body变量并获得"ho",我认为这是Sinatra窒息的原因。但我无法弄明白为什么。发布到其他服务器是成功的。关于我做错了什么想法?

我可以发布java代码但是,像往常一样java,它非常冗长。我也认为这不是问题,因为它确实成功发布到远程服务器,正如我所提到的。

1 个答案:

答案 0 :(得分:0)

post '/upload' do
    puts "*****************************************"
    puts "!!!!!!!! #{params.inspect}"
end

Sinatra将始终尝试使用上次返回的值作为要解析的数据,然后再将其作为http数据发送。 这里的最后一条指令是puts "!!!!!!!! #{params.inspect}",返回nil

post '/upload' do
    puts "*****************************************"
    puts "!!!!!!!! #{params.inspect}"
    "Information received"
end

这里Sinatra有一些字符串可供使用并且很开心