新手问题 ruby tcp/http 传输问题, 请问下怎么存储发过来的数据到数据库

xiaoxiao · February 26, 2013 · Last by xiaoxiao replied at February 26, 2013 · 2488 hits

require 'net/http' url = URI.parse('http://localhost:3000/products') Net::HTTP.start(url.host, url.port) do |http| req = Net::HTTP::Post.new(url.path) req.set_form_data( 'name' => 'David' ) req.basic_auth('username', 'password') puts http.request(req).body end ruby 这个文件在服务器端看到 Started POST "/products" for 127.0.0.1 at 2013-02-26 14:33:42 +0800 Processing by ProductsController#create as / Parameters: {"name"=>"David"} WARNING: Can't verify CSRF token authenticity (0.6ms) begin transaction (0.1ms) rollback transaction

利用这个程序可以在服务器段看有数据传过来,但是不能存到数据库里,怎么办,help

直接把 http.request(req).body 当字符串处理就行了

还是不懂,请大神赐教

You need to Sign in before reply, if you don't have an account, please Sign up first.