You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Mark Maunder <ma...@swiftcamel.com> on 2001/10/08 00:42:14 UTC

POST and GET and getting multiple unsynced requests

Hi all,

I've written a web app as a single mod_perl handler. I started writing
my forms so they would do a POST and GET simultaneously. I did this by
making the form method=POST  action="/job_details?job=65" for example.
Now I notice that IE and Netscape do a POST and GET request every time
the form is submitted (so I'm logging two requests for the same URI and
Mime type for each form submission. The first is GET and the second is
POST). My problem is that the data returned to the browser is from the
GET request. The page that is generated has content that is affected by
the POSTed data, but this is only visible on a refresh of the same page.

I've done tests with Netscape and IE. I consistently have this problem
with Netscape, and with IE it works most of the time, but approximatelly
every 20 requests, I'll get a page that is generated from the GET data,
not the POSTed data.

I've included a source snippit from my handler below. If anyone has seen
this before, I'd appreciate any help! (I scoured the guide and archive.
I'm really sorry if I missed it!)

--snip--
sub handler
{
        my $r = Apache::Request->new(shift @_);
        $r->log_error("Request being handled: " . $r->content_type() . "
- " . $r->uri() . " - " . $r->method());
        #We dont want to handle image, CSS or javascript requests
        if($r->content_type() =~ m/(^image|^text\/css|javascript)/)
        {
                return DECLINED;
        }
        my $dbh = FUtil::connect_database();
--end snippet--

And the error log shows:
[Sun Oct  7 23:05:38 2001] [error] Request being handled:  -
/job_details - GET
[Sun Oct  7 23:05:38 2001] [error] Request being handled:  -
/job_details - POST
[Sun Oct  7 23:05:38 2001] [error] Request being handled: text/css -
/style.css - GET
[Sun Oct  7 23:05:38 2001] [error] Request being handled:
application/x-javascript - /js.js - GET

The form HTML tag that did this was:
<form action="http://www.freeusall.com/job_details?job=61" method=POST
name="hotlist_form_jd_61">
This is doing a POST and GET.


Re: POST and GET and getting multiple unsynced requests

Posted by Mark Maunder <ma...@swiftcamel.com>.
> I think that's just a coincidence.  IIRC, the spec doesn't require this to
> work, and it doesn't work in all browsers.  The only real solution is to not
> do it.  PATH_INFO was a good suggestion.  I'd go with that if it can't be
> added to the POST data.

Thanks. I've taken your advice and am using a redirect after form submission to
the original URL (the URL with the GET args I was using in the form 'action'
attribute) as a workaround.

I can't use PATH_INFO (or $r->path_info() ) because I submit forms via GET at
various parts of the application so that users can bookmark the results (search
results for example).

Both browsers (IE and NS) seem to be submitting both a POST and GET request. In
the case of the POST request, the GET params are included in the URL and both
GET and POST params are accessable via $r->args() and $r->content respectivelly
(provided it is the POST request you're processing and not the GET - and you
can't be sure of which). I put a sniffer on the wire and the header of the GET
and POST requests looks like so:
POST /?step=10&search=Perl HTTP/1.1
GET /?step=10&search=Perl HTTP/1.1
(The POST request has the posted data included at the end of the header)
So it seems that it depends which request is received first. In the case of
netscape it's always the GET first and in the case of IE it is mostly the POST
first but it varies.



Re: POST and GET and getting multiple unsynced requests

Posted by Perrin Harkins <pe...@elem.com>.
> I've just created a form like that just for testing and it worked fine,
> (<form name="zbr" method="POST" action="/cgi-bin/printenv/zbr/?zbr=t">)

I think that's just a coincidence.  IIRC, the spec doesn't require this to
work, and it doesn't work in all browsers.  The only real solution is to not
do it.  PATH_INFO was a good suggestion.  I'd go with that if it can't be
added to the POST data.
- Perrin


Re: POST and GET and getting multiple unsynced requests

Posted by Luciano Miguel Ferreira Rocha <st...@nsk.yi.org>.
Hello

I've just created a form like that just for testing and it worked fine,
(<form name="zbr" method="POST" action="/cgi-bin/printenv/zbr/?zbr=t">)

I got only one POST /cgi-bin/printenv/zbr/?zbr=t and the ENV was correct:
REQUEST_METHOD="POST"
QUERY_STRING="zbr=t"
PATH_INFO="zbr"
CONTENT_LENGTH="42"

texto=aaaa&pass=bbbb&hdn=cccc&sub=Submeter

I'm not using modperl in this example, just a normal CGI, but I don't
think it would make any diference.

Anyway, could you check your access_log for both the POST and GET?

Also, consider using PATH_INFO instead of QUERY_STRING in a POST. After all,
that's one of the purposes of that thing...

hugs
Luciano Rocha

-- 
Luciano Rocha, strange@nsk.yi.org

The trouble with computers is that they do what you tell them, not what
you want.
                -- D. Cohen