Hi ,
i am new to Ruby on rails
I am writing code for calling Api code ..
I have written a post request ruby code for testing my Api blogs..
require 'net/http'
require 'uri'
url = URI.parse('http://localhost:3000/api/blogs/create.xml')
req = Net::HTTP::Post.new(url.path)
req.basic_auth 'a', 'a'
req.set_form_data({'blogpost[title]' => 'TestingAPIBlogposttitle' , 'blogpost[description]' => 'Testing api desc' })
res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
case res
when Net::HTTPSuccess, Net::HTTPRedirection
puts res.body
else
res.error!
end
The above code throws me an error of can't convert Hash into String (TypeError) /usr/lib/ruby/1.8/net/http.rb:2101:in `error!': 422 "" (Net::HTTPServerException)
why so ? how to rectify the error ..