# HTTP POST redirect

**URL:** <https://www.ruby-forum.com/t/http-post-redirect/85326>\
**Category:** Rails\
**Created:** [February 12, 2007, 6:33pm UTC](https://www.ruby-forum.com/t/http-post-redirect/85326 "2007-02-12T18:33:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [February 12, 2007, 6:33pm UTC](https://www.ruby-forum.com/t/http-post-redirect/85326/1 "2007-02-12T18:33:37Z")

</div>

Is there a way to create an HTTP POST redirect? So when the user is  
redirected, the browser visits that URL but POSTs to it instead of  
GETting it.

Pat

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [February 12, 2007, 6:47pm UTC](https://www.ruby-forum.com/t/http-post-redirect/85326/2 "2007-02-12T18:47:28Z")

</div>

Pat M. wrote:

> Is there a way to create an HTTP POST redirect? So when the user is  
> redirected, the browser visits that URL but POSTs to it instead of  
> GETting it.
> 
> Pat

I think if the browsers sends a POST and then gets a 301 redirect  
response, the browser will POST the same thing to the redirected url as  
well.

I don’t think there is a way to force the browser to send a POST after  
being redirected from a GET.

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [February 12, 2007, 9:57pm UTC](https://www.ruby-forum.com/t/http-post-redirect/85326/3 "2007-02-12T21:57:12Z")

</div>

On 2/12/07, Alex W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> well.  
> I just did a brief demo and the browser will GET the redirected URL.  
> Bummer. Any other ideas?

Pat

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [February 12, 2007, 10:04pm UTC](https://www.ruby-forum.com/t/http-post-redirect/85326/4 "2007-02-12T22:04:13Z")

</div>

You can try doing this using curl. This example is in php but  
there’s a ruby lib out there too.

$g = curl\_init();  
curl\_setopt($g,CURLOPT\_URL,‘[http://urltopostto.com](http://urltopostto.com)’);  
curl\_setopt($g, CURLOPT\_POST, 1);  
curl\_setopt($sessions,CURLOPT\_POSTFIELDS,"foo=bar&andy=cool);  
print curl\_exec($g);

You could also do this by loading a page using a GET then using  
javascript to click on a form post button on the window load.

Andy
