debug cgi programs with post forms

Discussion in 'Perl Misc' started by david, Nov 20, 2008.

  1. david

    david Guest

    Hi all,

    How do i debug cgi programs where the html contains a post form ?
    If it contains a get form it is easy because i can run perl -d from
    the command line.
    In this case i have a very large form with many variables and it is a
    post form.
    How can i debug it ?
    I made a google search and found answers like printing the environment
    variables and then run it like a get command with perl -d but this is
    a bit tedious.
    Is there a "best practice" for this type of problem ?


    Thanks in advance,
    David
    david, Nov 20, 2008
    #1
    1. Advertising

  2. david

    Guest

    Try using Data::Dumper module.

    --------
    use CGI;
    use Data::Dumper;

    my $query= new CGI();
    print $query->header();
    print Data::Dumper->Dump([$query]);

    ----------

    This should give you all information into your browser.


    -Sopan Shewale
    (http://sopanshewale.blogspot.com)




    On Nov 20, 2:38 pm, david <> wrote:
    > Hi all,
    >
    > How do i debug cgi programs where the html contains a post form ?
    > If it contains a get form it is easy because i can run perl -d from
    > the command line.
    > In this case i have a very large form with many variables and it is a
    > post form.
    > How can i debug it ?
    > I made a google search and found answers like printing the environment
    > variables and then run it like a get command with perl -d but this is
    > a bit tedious.
    > Is there a "best practice" for this type of problem ?
    >
    > Thanks in advance,
    > David
    , Nov 20, 2008
    #2
    1. Advertising

  3. david

    smallpond Guest

    On Nov 20, 4:38 am, david <> wrote:
    > Hi all,
    >
    > How do i debug cgi programs where the html contains a post form ?
    > If it contains a get form it is easy because i can run perl -d from
    > the command line.
    > In this case i have a very large form with many variables and it is a
    > post form.
    > How can i debug it ?
    > I made a google search and found answers like printing the environment
    > variables and then run it like a get command with perl -d but this is
    > a bit tedious.
    > Is there a "best practice" for this type of problem ?
    >
    > Thanks in advance,
    > David



    http://search.cpan.org/dist/CGI.pm/CGI.pm#DEBUGGING

    CGI has a -debug mode that should allow you to emulate POST input
    from
    the command line. I haven't tried it, so I have no idea what it does
    about the CONTENT_LENGTH stuff. The alternative would be to set
    CONTENT_LENGTH and open a file of your POST data on STDIN.
    smallpond, Nov 20, 2008
    #3
  4. david

    Guest

    david <> wrote:
    > Hi all,
    >
    > How do i debug cgi programs where the html contains a post form ?
    > If it contains a get form it is easy because i can run perl -d from
    > the command line.
    > In this case i have a very large form with many variables and it is a
    > post form.


    Does it have file upload fields?

    > How can i debug it ?


    What kind of bugs are you looking for?

    > I made a google search and found answers like printing the environment
    > variables and then run it like a get command with perl -d but this is
    > a bit tedious.
    > Is there a "best practice" for this type of problem ?


    I find the best practice is not making bugs in the first place. :)

    I also often add code to the CGI to process secret debugging parameter,
    which turns on strategically placed extra print or warn statements.

    warn "Now I'm doing $foo" if $cgi->url_param('debug');

    If you really want to debug under -d, then you can run the program using
    $cgi->save($file_handle) to save the query and then perl -d script.cgi <
    saved_query_file

    (this won't work with file upload fields, as the file contents are not
    saved.)

    Where the script use CGI has been changed to something like:
    use CGI qw(-debug);

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    The costs of publication of this article were defrayed in part by the
    payment of page charges. This article must therefore be hereby marked
    advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
    this fact.
    , Nov 20, 2008
    #4
  5. david

    david Guest

    I am not using file upload fields, so the option of $cgi->save
    ($file_handle) to save the query and then perl -d script.cgi <
    saved_query_file to run the query will be great

    Thank you very much

    On Nov 20, 6:27 pm, wrote:
    > david <> wrote:
    > > Hi all,

    >
    > > How do i debug cgi programs where the html contains a post form ?
    > > If it contains a get form it is easy because i can run perl -d from
    > > the command line.
    > > In this case i have a very large form with many variables and it is a
    > > post form.

    >
    > Does it have file upload fields?
    >
    > > How can i debug it ?

    >
    > What kind of bugs are you looking for?
    >
    > > I made a google search and found answers like printing the environment
    > > variables and then run it like a get command with perl -d but this is
    > > a bit tedious.
    > > Is there a "best practice" for this type of problem ?

    >
    > I find the best practice is not making bugs in the first place. :)
    >
    > I also often add code to the CGI to process secret debugging parameter,
    > which turns on strategically placed extra print or warn statements.
    >
    > warn "Now I'm doing $foo" if $cgi->url_param('debug');
    >
    > If you really want to debug under -d, then you can run the program using
    > $cgi->save($file_handle) to save the query and then perl -d script.cgi <
    > saved_query_file
    >
    > (this won't work with file upload fields, as the file contents are not
    > saved.)
    >
    > Where the script use CGI has been changed to something like:
    > use CGI qw(-debug);
    >
    > Xho
    >
    > --
    > --------------------http://NewsReader.Com/--------------------
    > The costs of publication of this article were defrayed in part by the
    > payment of page charges. This article must therefore be hereby marked
    > advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
    > this fact.
    david, Nov 20, 2008
    #5
  6. david

    david Guest

    On Nov 20, 6:27 pm, wrote:
    > david <> wrote:
    > > Hi all,

    >
    > > How do idebugcgiprograms where the html contains a post form ?
    > > If it contains a get form it is easy because i can run perl -d from
    > > the command line.
    > > In this case i have a very large form with many variables and it is a
    > > post form.

    >
    > Does it have file upload fields?
    >
    > > How can idebugit ?

    >
    > What kind of bugs are you looking for?
    >
    > > I made a google search and found answers like printing the environment
    > > variables and then run it like a get command with perl -d but this is
    > > a bit tedious.
    > > Is there a "best practice" for this type of problem ?

    >
    > I find the best practice is not making bugs in the first place. :)
    >
    > I also often add code to theCGIto process secret debugging parameter,
    > which turns on strategically placed extra print or warn statements.
    >
    > warn "Now I'm doing $foo" if $cgi->url_param('debug');
    >
    > If you really want todebugunder -d, then you can run the program using
    > $cgi->save($file_handle) to save the query and then perl -d script.cgi<
    > saved_query_file
    >
    > (this won't work with file upload fields, as the file contents are not
    > saved.)
    >
    > Where the script useCGIhas been changed to something like:
    > useCGIqw(-debug);
    >
    > Xho
    >
    > --
    > --------------------http://NewsReader.Com/--------------------
    > The costs of publication of this article were defrayed in part by the
    > payment of page charges. This article must therefore be hereby marked
    > advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
    > this fact.


    I have now another problem. The $cgi->save($file_handle) does not save
    cookie data. How it is possible to work with it when using also cookie
    data ?
    david, Dec 9, 2008
    #6
    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. Replies:
    12
    Views:
    1,638
    Dave Thompson
    Jan 10, 2005
  2. Sullivan WxPyQtKinter

    debug CGI with complex forms

    Sullivan WxPyQtKinter, Apr 6, 2006, in forum: Python
    Replies:
    1
    Views:
    327
    R. Bernstein
    Apr 8, 2006
  3. Coca
    Replies:
    7
    Views:
    736
    Aidan Grey
    Aug 24, 2004
  4. Replies:
    18
    Views:
    619
    Dave Thompson
    Jan 10, 2005
  5. Mr I
    Replies:
    13
    Views:
    351
Loading...

Share This Page