Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

LWP/Post with several arguments

by scain (Curate)
on Mar 04, 2002 at 20:57 UTC ( [id://149212]=perlquestion: print w/replies, xml ) Need Help??

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

Goodday Fine Monks,

I am working on a script that uses LWP to submit a form via POST to a cgi and collect the results. I realize that this topic has been covered before, and many have suggested perldoc lwpcook, which I have read. Nevertheless, I feel I must be missing something, as my script still does not work. At the moment I am getting an error message that looks like this:

500 (Internal Server Error) Not a SCALAR reference Client-Date: Mon, 04 Mar 2002 20:42:13 GMT
I assume the not a SCALAR reference is coming straight from perl, as it is trying to print something that doesn't exist.

I am designing this to work on an internal server, but I changed my non working script to run against a similarly configured server at UCSF. Please don't everybody run this script against their server, as I haven't cleared it with them, so if 100 of us hit it all at once, it may go down.

Ok, here the script:

#!/usr/bin/perl -w use strict; use Getopt::Std; use LWP::UserAgent; use HTTP::Request::Common qw(POST); use vars qw($ua); my %opts; getopts('hp:d:i:o:e:v:b:F:', \%opts); my $PROGRAM = $opts{'p'}; my $DB = $opts{'d'}; my $INFILE = $opts{'i'}; my $OUTFILE = $opts{'o'}; my $ESCORE; my $V; my $B; my $F; if (defined $opts{'e'}) { $ESCORE=$opts{'e'}; } else { $ESCORE=0.01; } if (defined $opts{'v'}) { $V=$opts{'v'}; } else { $V=10; } if (defined $opts{'b'}) { $B=$opts{'b'}; } else { $B=10; } if (defined $opts{'F'}) { $F=$opts{'F'}; } else { $F='T'; } #-------------------------------------------------------------- my $seq="GCAGCAGGTCGGTAGGCGGGAAATGGCGACTGGCTGAAGGAGCTGGTTCTGTTGCTGCTGC +GGGGTAAGCGGGAAAGACACCACACA"; $DB = 'baygenomicsdb'; $ua = LWP::UserAgent->new; my $req = HTTP::Request->new(POST => 'http://baygenomics.ucsf.edu/db/c +gi-bin/blast/blast.cgi'); $req->content_type('form-data'); #also tried 'application/x-www-form-u +rlencoded' $req->content( [ PROGRAM => $PROGRAM, DATALIB => $DB, SEQUENCE => $seq, EXPECT => $ESCORE, DESCRIPTIONS => $V, ALIGNMENTS => $B ]); print $ua->request($req)->as_string;
The script get executed like this on the command line:
$ ./test-post.pl -p blastn -d hs_all.fa -i test.in -o test.out
Currently, the -d, -i and -o flags are not used even though they are specified.

Thanks for your time.
Scott

Replies are listed 'Best First'.
Re: LWP/Post with several arguments
by gav^ (Curate) on Mar 04, 2002 at 21:10 UTC
    This should work:
    my $data = [PROGRAM => $PROGRAM, etc...]; my $action = 'http://baygenomics.ucsf.edu/db/cgi-bin/blast/blast.cgi'; my $res = $ua->request(POST($action, $data)); if ($res->is_success) { print $res->content; } else { print "Error: ", $res->status_line, "\n"; }

    gav^

      Thanks, that mostly seems to have done the trick. I at least am getting a response from the web server now, though I am apparently not giving it enough information yet, as the cgi throws an error at me. Fortunatly, I ducked in time, as I have fairly quick reflexes.

      Thanks again,
      Scott

        ++ for humour

        ..Guv

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://149212]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2024-09-17 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (22 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.