LWP Strdup Problem

L

lichtenj

I am trying to automatically submit a form to a website. While my setup
works for all other pages i submit to, one page returns "In fct
"Strdup" : Invalid argument".
I tried submitting the cookie the page saved when i am using the form
on the web.

This is where i am submitting my variables, stored in a parameter hash
called submit, to the website:

my $cookie_jar = HTTP::Cookies->new(
file => '(e-mail address removed)',
);

my $ua = LWP::UserAgent->new();
$ua->cookie_jar($cookie_jar);

my $req = POST $url, [$submit];
my $content = $ua->request($req)->as_string;

if ( $content )
{
if ( open(RESP, ">$htm") )
{
print RESP $content;
close RESP;
print "$htm written\n"
}
else
{
print "Opening $htm: $!\n";
}
}
else
{
print "Website submission failed\n";
}

All i could find about Strdup was that it is used for string
duplication and some sort of fake request checking in Apache.

Any help you can give me is highly appreciated.
 
T

Tad McClellan

stored in a parameter hash
called submit

my $req = POST $url, [$submit];
^^^^ ^^^^^^^

You have never put a value into either of those variables.

If $submit is a reference to a hash, then you need
to de-reference it:

my $req = POST $url, [ %$submit ];


if ( open(RESP, ">$htm") )
{
print RESP $content;
close RESP;
print "$htm written\n"
}
else
{
print "Opening $htm: $!\n";
}


Error messages should go on STDERR, not STDOUT.

Any help you can give me is highly appreciated.


We could surely help if you had posted a short and complete
program that we could run that illustrates the problem...
 
L

lichtenj

Here is a complete working (well actually not really) example of my
problem:

use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use Data::Dumper;

my $result = lwp();

sub lwp
{
my $htm = "results.html";

# submit to ms site
{
my $url = parameter()->{MS}->{url};
my $submit = parameter()->{MS}->{submit};

$submit->{'precision'} = '1|Monoisotopic';

$submit->{'peakList'} = '978.51513671875';

my $ua = LWP::UserAgent->new();
my $req = POST $url, [%$submit];
my $content = $ua->request($req)->as_string;

if ( $content )
{
#print Data::Dumper->Dump([$content]);
print $content;
}
else
{
print "Website submission failed\n";
}
}
}

sub parameter
{
return
{
'MS' =>
{
'execute' => 0,
'url' => 'http://www.expasy.org/cgi-bin/aldente/form.cgi',

'submit' =>
{
'nbRandTryMax' => '100000',
'modifAdd' => 'C2H4ON',
'errorPpm' => '25',
'modifMode' => '0|Fixed',
'kwList' => '',
'UseScoringI' => '1',
'UseScoringCTermLimit' => '1',
'deltaDa' => '0.2',
'modifUseScore0' => '1',
'kwMode' => '0|Or',
'modifUseScore1' => '1',
'ScoringCoverage' => '1',
'ScoringCTermK' => '0.5',
'modifSupp' => 'H',
'outputFormat' => '0|HTML',
'UseScoringCTermK' => '1',
'nbMaxProtein' => '15',
'onlyTaxid' => '',
'pvalueThreshold' => '1e-5',
'ScoringCTermLimit' => '5',
'uploadParam' => '',
'mwMax' => '100000',
'ptmList' => '0|Observed',
'proton' => '0|[M+H]',
'UseScoringMC' => '1',
'ScoringMw' => '1',
'helpTarget' => '',
'peptideSort' => '1|By position',
'SpleMw' => '0',
'ScoringPi' => '1',
'nbCoupleMin' => '4',
'sampleSort' => '0|by mass',
'uploadFile' => '',
'ScoringMC' => '0.5',
'deltaPpm' => '200',
'nbModif' => '2',
'SplePi' => '',
'fileType' => '0|pkm',
'piMax' => '14',
'requestId' => '0',
'ScoringIntensity' => '1',
'UseScoringCTermR' => '1',
'displayHelp' => '1',
'menuTab' => '2',
'SpleName' => 'Unknown',
'varsplice' => '1',
'modifLabel' => 'CAM',
'fragment' => '1',
'mwMin' => '0',
'UseScoringPi' => '1',
'enzyme' => '0|Trypsin',
'piMin' => '0',
'DataBase' => '0|UniProtKB/Swiss-Prot',
'nbRandFindMin' => '3000',
'mail' => '',
'modifTolerance' => '1',
'modifLocus' => 'C',
'missedCleavage' => '1|1',
'UseScoringMw' => '1',
'ScoringCTermR' => '1.5',
'UseScoringCoverage' => '1',
'modifScore' => '0.3',
'SeqSimilarity' => '3|50%',
'ptmTolerance' => '2'
},
},
}
};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top