Ruby on Rails Monday, January 31, 2011

Douglas,

I dont know what error occurs, but how'bout this code?

require "uri"
require "net/http"

params = {"box1" => "Nothing is less important than which fork you
use.
Etiquette is the science of living. It embraces everything. It is
ethics. It
is honor. -Emily Post", "button1" => "Submit"}

Net::HTTP.start('http://localhost:3000', 80) {|http|
response = http.post('/', params)
puts response.body
}

Hope this would work well.

On 1月31日, 午後11:10, Douglas Fonseca <douglasinfo...@gmail.com> wrote:
> How can I send a post request to an external server from my app controller?
> I tried with this but didn't work:
>   require "uri"
>   require "net/http"
> params = {"box1" => "Nothing is less important than which fork you use.
> Etiquette is the science of living. It embraces everything. It is ethics. It
> is honor. -Emily Post",
>     "button1" => "Submit"}
>     x = Net::HTTP.post_form(URI.parse("http://localhost:3000"),params)
>     puts x.body
> Thanks in advance!
> ---------------------------------------------------
> Douglas Fonseca
> Engenharia da Computação 2010
> Universidade Estadual de Campinas

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment