GETS and POSTS and existing query strings
am 17.01.2008 00:41:44 von ML
Hi,
I've got a unique situation I need some advice on. I have a program
that reads a webpage, and strips all the html out of it to make each link
something like :
http://www.example.com/cgi-bin/example.pl?next=wtgb435&sid=g 2245er
Program uses LWP and works like a champ.
So next I wanted to move into having it handle forms. This is
where I'm running into a problem.
If I try to view a GET, I end up with :
email
Submit
Key - email / Data - GETIT
Key - Submit / Data - Send
email=GETIT&Submit=Send
Which I lose my information completely.
If I use a POST, I end up with :
email
Submit
Key - email / Data - POSTIT
Key - Submit / Data - Send
next=W9vmYnV8NW0nJ4Vvmt2vGpwvouo281wP&sid=8TviPDfR4LhVA5WvjP r63Ppm2aPWMiNl
Which I get my data in the QUERY_STRING, and the other data via
the params.
Is there a way I can uniformly get what I need, regardless of a
GET or a POST?
Thanks, Tuc
CGI:
#!/usr/bin/perl
use CGI;
$cgiinfo= new CGI;
@paramnames = $cgiinfo->param;
print "Content-Type: text/plain; charset=US-ASCII\n\n";
print join("\n",@paramnames);
foreach $key (@paramnames)
{
print "Key - $key / Data - ".$cgiinfo->param($key)."\n";
}
print $ENV{'QUERY_STRING'};
HTML:
Testing page
GET here
POST here
Re: GETS and POSTS and existing query strings
am 28.01.2008 02:20:17 von ML
> On 1/16/08, Tuc at T-B-O-H.NET wrote:
> >
> > Which I get my data in the QUERY_STRING, and the other data via
> > the [POST] params.
> >
> > Is there a way I can uniformly get what I need, regardless of a
> > GET or a POST?
> >
>
> It sounds like you're trying to mix GET and POST. I believe this is what
> you're looking for, from the CGI documentation:
>
> MIXING POST AND URL PARAMETERS
>
> $color = url_param('color');
>
> It is possible for a script to receive CGI parameters in the URL as
> well as in the fill-
> out form by creating a form that POSTs to a URL containing a query
> string (a "?" mark fol<80><90>
> lowed by arguments). The param() method will always return the
> contents of the POSTed
> fill-out form, ignoring the URL's query string. To retrieve URL
> parameters, call the
> url_param() method. Use it in the same way as param(). The main
> difference is that it
> allows you to read the parameters, but not set them.
>
> Under no circumstances will the contents of the URL query string
> interfere with similarly-
> named CGI parameters in POSTed forms. If you try to mix a URL query
> string with a form
> submitted with the GET method, the results will not be what you
> expect.
>
> The last sentence is important as well, because you're providing the browser
> with a URL that has a query string, and asking it to submit a form with the
> GET method. This will cause the browser to replace the existing query
> string with a new query string.
>
> Have you considered using hidden input fields to pass your 'next' and 'sid'
> parameters? That way they will be passed with the rest of the data.
>
> David
>
Hi,
I wasn't trying to mix GET/POST on purpose. I was being forced
since I was trying to make sure my "next" and "sid" were there, be it a
form, HREF, SRC, etc. I did end up "changing my ways".
I forgot that you can do something like :
/cgi-bin/mycgi.pl/start_or_next/sid
So now if there is a query string, I just get :
/cgi-bin/mycgi.pl/start_or_next/sid?field=value
so it solved my issue of POSTing with a URL query string OF MY OWN.
So as they say, its "all good". :)
As for inserting it into the form, I didn't want to try that on the
fly. I was having enough issues trying to parse/replace text in the pages
I got. I actually had to sort the data longest to shortest to make sure
that when I did my search/replace I didn't do a "sub replace" where it
shouldn't be.
I'd love to know if there is a way to call HTML::LinkExtor in a
search/replace mode. If anyone knows, I'd be quite interested.
Thanks, Tuc