mt2k has asked for the wisdom of the Perl Monks concerning the following question:

What I want to do is to be able to specify the method that the browser retrieves a web document.
I definitely want to use this to do it with:
print "Location: $url_to_go_to\n\n";
So all I need is to know how to set the retrieval method to GET or POST for the document located at $url_to_go_to.
Thanks in advance for your help, fellow monks!

Replies are listed 'Best First'.
Re: Setting Retrieve Method
by chromatic (Archbishop) on Jun 17, 2000 at 01:00 UTC
    As far as I know, your one option is GET. As the Location: header is in the headers, there's nothing *to* POST.

    Again, as far as I know, the only way to do a POST action -- through a browser -- is using an HTML form. If you want to automate this, you'll have to look into something like client-side JavaScript.

    Update:

    Per merlyn's gentle and subtle recommendation below, I perused the relevant RFCs. RFC 1945 says:

    If the 301 status code is received in response to a request using the POST method, the user agent must not automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued.
    RFC 2068 repeats this, in stronger language. It looks like RFC-compliant browsers *have* to ask users if they wish to resubmit form data when being redirected.
RE: Setting Retrieve Method
by merlyn (Sage) on Jun 17, 2000 at 02:12 UTC
    OK, trying again not to get my nerves too twisted up, but most of the answers here are from people that haven't read the RFCs.

    The HTTP RFCs permit the use of

    Method: POST
    to change the method on the redirect with location. Admittedly, this is used mostly for changing from POST to GET, but I don't see any reason why this wouldn't work in the other direction.

    -- Randal L. Schwartz, Perl hacker

RE: Setting Retrieve Method
by Ovid (Cardinal) on Jun 17, 2000 at 00:11 UTC
    I'm not sure exactly what you're asking, but I'll take a stab at what I think you're asking.

    If you're printing a URL to a Web page and that URL is accessing a script, you pass values to the script with the GET method. This puts the name/value pairs in the URL.

    http://somedomain.com/some.cgi?system=windows&opinion=sucks
    The above url will pass
    system=windows opinion=sucks
    to your CGI script via the GET method. Note: Those name value pairs will not magically appear if you're just printing the URL. You'll need to specify them directly in the URL or create a form (with method=get) with a submit button and pass the values that way.

    If you need to pass these values to your script via the POST method (and have the name/value pairs sent separately from the URL), you'll need to create a form and specify method=post

Re: Setting Retrieve Method
by btrott (Parson) on Jun 17, 2000 at 01:01 UTC
    Update: some nonsense about Location: being unable to use POST has been deleted. I'll leave this, though, as it's still a valid option:

    Another, different option would be to use LWP to fetch the web page (where you could use either GET or POST), then print that out to the web browser.

Re: Setting Retrieve Method
by Aighearach (Initiate) on Jun 17, 2000 at 00:18 UTC

    This comment deprecated.

    It is longer current to downvote here. Please find something new to pick on.

    It's funny, laugh.

     

     

    Thank You