how to send multiple parameters in the req.set_form_data

  • Thread starter Aruna Chinnamuthu
  • Start date
A

Aruna Chinnamuthu

Hi ,

I am writing ruby code for calling APIs ..

i am writing the POST request form .

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


This shows me an error like
/usr/lib/ruby/1.8/net/http.rb:2101:in `error!': 422 ""
(Net::HTTPServerException)
from post_req.rb:13

My Table Structure is like

Blogpost(id,title,slug,description,created_at,category)
 
B

Brian Candler

Aruna said:
This shows me an error like
/usr/lib/ruby/1.8/net/http.rb:2101:in `error!': 422 ""
(Net::HTTPServerException)
from post_req.rb:13

Are you talking to a Rails app by any chance? Rails uses 422 to mean
that the authenticity token is missing from the form, which protects
against CSRF.

Read about it in
actionpack/lib/action_controller/metal/request_forgery_protection.rb

You should also see the error in your server log (if you have access to
the server side that is)
My Table Structure is like

Blogpost(id,title,slug,description,created_at,category)

This is a list for Ruby, the programming language. Rails questions are
best asked on a Rails list. Rails and Ruby are not the same thing; Rails
just happens to be written *in* Ruby.

Regards,

Brian.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top