# Can a server make a post to itself?

**URL:** <https://www.ruby-forum.com/t/can-a-server-make-a-post-to-itself/184218>\
**Category:** Rails\
**Created:** [February 26, 2010, 8:30pm UTC](https://www.ruby-forum.com/t/can-a-server-make-a-post-to-itself/184218 "2010-02-26T20:30:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dino\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dino\_d](https://www.ruby-forum.com/u/dino_d)\
**Post date:** [February 26, 2010, 8:30pm UTC](https://www.ruby-forum.com/t/can-a-server-make-a-post-to-itself/184218/1 "2010-02-26T20:30:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dino\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dino\_d](https://www.ruby-forum.com/u/dino_d)\
**Post date:** [February 26, 2010, 10:10pm UTC](https://www.ruby-forum.com/t/can-a-server-make-a-post-to-itself/184218/2 "2010-02-26T22:10:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dino\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dino\_d](https://www.ruby-forum.com/u/dino_d)\
**Post date:** [February 27, 2010, 7:39pm UTC](https://www.ruby-forum.com/t/can-a-server-make-a-post-to-itself/184218/3 "2010-02-27T19:39:20Z")

</div>

On Feb 26, 2:29 pm, “dino d.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.
