Can a server make a post to itself?

Hi-

I have a rails app where a form gets submitted, and that data from the
form has to be validated. It’s a widget app, so other sites will use
the validation routine, but I also want to use it myself, from the
same server that does the validation. So, is it possible for a ruby
instance to send a post to the same server? I try this in development
but it freezes up and I eventually get a timeout error. The code
looks like this:

def verify_home
@response = “An error has occurred.”
if params[:widget_id] and params[:widget_answer]
result = Net::HTTP.post_form(URI.parse(‘http://localhost:3000/
questions/verify’),
{‘widget_id’ => params[:widget_id], ‘widget_answer’ =>
params[:widget_answer])
if result.include? “success”
@response = “Correct!”
end
end
redirect_to :action => “index”
end

So, the “questions/verify” method works just fine on its own (when
submitted from a different site), but freezes up when I send it from
the current server to itself.

Any advice?

Thanks,
Dino

On Feb 26, 2010, at 11:29 AM, dino d. wrote:

def verify_home
redirect_to :action => “index”
end

So, the “questions/verify” method works just fine on its own (when
submitted from a different site), but freezes up when I send it from
the current server to itself.

Any advice?

Any chance you are using webrick? Webrick is single threaded and
won’t handle multiple requests at the same time. Try running it with
mongrel or something else that can handle multiple requests at the
same time.

There’s no reason you can’t do what you’re trying to do.

Although, if you’re verifying against yourself it will be a lot faster
to call the ruby method/routine that does it instead of posting back
to yourself. Net::HTTP is slow.

-philip

On Feb 26, 2:29 pm, “dino d.” [email protected] wrote:

def verify_home
redirect_to :action => “index”
end

So, the “questions/verify” method works just fine on its own (when
submitted from a different site), but freezes up when I send it from
the current server to itself.

You’re probably better off just calling the model method that
questions/verify calls - you could even refactor the parameter parsing
into a method on ApplicationController if verify_home isn’t in the
same class.

–Matt J.