# How to send multiple parameters in the req.set\_form\_data

**URL:** <https://www.ruby-forum.com/t/how-to-send-multiple-parameters-in-the-req-set-form-data/194562>\
**Category:** Ruby\
**Created:** [September 7, 2010, 8:08am UTC](https://www.ruby-forum.com/t/how-to-send-multiple-parameters-in-the-req-set-form-data/194562 "2010-09-07T08:08:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![arunachandu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d6d6ee/32.png) [@arunachandu](https://www.ruby-forum.com/u/arunachandu)\
**Post date:** [September 7, 2010, 8:08am UTC](https://www.ruby-forum.com/t/how-to-send-multiple-parameters-in-the-req-set-form-data/194562/1 "2010-09-07T08:08:42Z")

</div>

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](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)

---

<div class="post-metadata">

**Author:** ![arunachandu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d6d6ee/32.png) [@arunachandu](https://www.ruby-forum.com/u/arunachandu)\
**Post date:** [September 7, 2010, 10:06am UTC](https://www.ruby-forum.com/t/how-to-send-multiple-parameters-in-the-req-set-form-data/194562/2 "2010-09-07T10:06:54Z")

</div>

Aruna C. wrote:

> 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.

---

<div class="post-metadata">

**Author:** ![arunachandu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d6d6ee/32.png) [@arunachandu](https://www.ruby-forum.com/u/arunachandu)\
**Post date:** [September 7, 2010, 10:38am UTC](https://www.ruby-forum.com/t/how-to-send-multiple-parameters-in-the-req-set-form-data/194562/3 "2010-09-07T10:38:54Z")

</div>

unsubscribe
