cgi.header redirect

Discussion in 'Ruby' started by Haris Bogdanovic, May 6, 2008.

  1. Hi!

    I tried to redirect a html page to itself to avoid browser's question about
    resending post data but it doesn't work.
    I tried this:

    cgi=CGI.new
    cgi.header('status'=>'302 moved', 'location'=>'my_page.rb')
    or
    cgi.header('status'=>'REDIRECT', 'location'=>'my_page.rb')

    The browser still asks the question about post data when I click the Refresh
    button

    Maybe someone knows why this doesn't work ?

    Thank you.
     
    Haris Bogdanovic, May 6, 2008
    #1
    1. Advertising

  2. Haris Bogdanovic

    Peter Jones Guest

    "Haris Bogdanovic" <> writes:
    > I tried to redirect a html page to itself to avoid browser's question about
    > resending post data but it doesn't work.
    > I tried this:
    >
    > cgi=CGI.new
    > cgi.header('status'=>'302 moved', 'location'=>'my_page.rb')
    > or
    > cgi.header('status'=>'REDIRECT', 'location'=>'my_page.rb')
    >
    > The browser still asks the question about post data when I click the Refresh
    > button


    The browser is doing the right thing. It doesn't matter that the
    result of a POST was a redirect (which is very common).

    If you click the refresh button after a POST, the browser will want to
    redo the POST. It of course asks if you want to POST the same data,
    which is good (especially if you just posted your credit card number).

    There are two ways around this, depending on what you are trying to
    do. If you are just trying to refresh the page by hand without the
    warning box, click in the location bar and press return.

    If you want to refresh automatically, without the warning box, add a
    meta refresh tag to the HTML.

    --
    Peter Jones [pjones at domain below]
    pmade inc. - http://pmade.com
     
    Peter Jones, May 10, 2008
    #2
    1. Advertising

  3. Haris Bogdanovic

    Kai Krakow Guest

    On 10 Mai, 19:40, Peter Jones <> wrote:
    > "Haris Bogdanovic" <> writes:
    > > I tried to redirect a html page to itself to avoid browser's question about
    > > resending post data but it doesn't work.
    > > I tried this:

    >
    > > cgi=CGI.new
    > > cgi.header('status'=>'302 moved', 'location'=>'my_page.rb')
    > > or
    > > cgi.header('status'=>'REDIRECT', 'location'=>'my_page.rb')

    >
    > > The browser still asks the question about post data when I click the Refresh
    > > button

    >
    > The browser is doing the right thing. It doesn't matter that the
    > result of a POST was a redirect (which is very common).
    >
    > If you click the refresh button after a POST, the browser will want to
    > redo the POST. It of course asks if you want to POST the same data,
    > which is good (especially if you just posted your credit card number).
    >
    > There are two ways around this, depending on what you are trying to
    > do. If you are just trying to refresh the page by hand without the
    > warning box, click in the location bar and press return.
    >
    > If you want to refresh automatically, without the warning box, add a
    > meta refresh tag to the HTML.


    According to http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
    you may want to try a 303 code... But unless request type is HEAD
    (which it is probably not in your case) you should also reply with
    some short HTML text.

    Regards,
    Kai
     
    Kai Krakow, May 11, 2008
    #3
  4. Haris Bogdanovic wrote:
    > I tried this:
    >
    > cgi=CGI.new
    > cgi.header('status'=>'302 moved', 'location'=>'my_page.rb')
    > or
    > cgi.header('status'=>'REDIRECT', 'location'=>'my_page.rb')


    You need both a '302' line and a 'Location' header. (btw, according to
    refs the url needs to be absolute.)

    >
    > Maybe someone knows why this doesn't work ?


    Why did you try 'REDIRECT'?

    You simply guessed?

    Then why didn't you guess 'Boozoonga'? or 'Kalibula'?

    It's nice to invent things, but don't expect your browser to understand
    you.

    Peter Jones wrote:
    > The browser is doing the right thing.


    Yes, but Haris's is a very valid wish. The Drupal CMS redirects after a
    form post, and I think it's indeed a good thing to do.
    --
    Posted via http://www.ruby-forum.com/.
     
    Albert Schlef, May 11, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. FLUX (a l'Ircam)

    CGI, header, and redirect

    FLUX (a l'Ircam), Jan 30, 2004, in forum: Perl
    Replies:
    1
    Views:
    613
    FLUX (a l'Ircam)
    Jan 30, 2004
  2. =?Utf-8?B?VHJveQ==?=

    Response.redirect does not redirect from .aspx page

    =?Utf-8?B?VHJveQ==?=, Oct 18, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    5,326
    Srowe1975
    Oct 15, 2008
  3. mlt
    Replies:
    2
    Views:
    890
    Jean-Marc Bourguet
    Jan 31, 2009
  4. Sal
    Replies:
    1
    Views:
    896
  5. Ron Howard
    Replies:
    2
    Views:
    553
    Ron Howard
    Aug 11, 2004
Loading...

Share This Page