Re: HTTP request arguments/content

2007-01-30 Thread David Landgren
Marijn Pessers wrote:
> Hello Bill,
>
> Thanks for your response, but something still is wrong.
>
> When I try your code (I checked and as far as I can see I adapted mine to
> your example) I get this error message:
>
> Can't call method "content" on an undefined value at
> ./neopost_fetch_machinetype_new.pl line 98,  line 1.
>
>   

That' s because the method request such as in


>   my $res = $ua->request($req);
>   

failed in some way and therefor returned undef. You can't call a method 
on undef, which is what the message above is indicating.

___
Perl-Win32-Web mailing list
Perl-Win32-Web@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: HTTP request arguments/content

2007-01-30 Thread Bill Luebkert
Marijn Pessers wrote:
> Hello Bill,
> 
> Thanks for your response, but something still is wrong.
> 
> When I try your code (I checked and as far as I can see I adapted mine to
> your example) I get this error message:

As far as I can see isn't good enough.

> Can't call method "content" on an undefined value at
> ./neopost_fetch_machinetype_new.pl line 98,  line 1.
> 
> FILEHANLDE is the file I get the value from...
> 
> The code in the row that goes wrong is the following:
>   return $res->content;
> 
> I printed $res and got this result:
> HTTP::Response=HASH(0x858bb9c)

That should be OK.  Try dumping it instead and see if it's a response
object.  EG:
use Data::Dumper; $Data::Dumper::Indent=1; $Data::Dumper::Sortkeys=1;
print Data::Dumper->Dump([$res], [qw($res)]);

> I think I can't call content directly from the $res. What must change?

If $res is indeed a response object, you should be fine.

Run my code exactly as is and only modify the $remote and $path to
the proper values.  Then if that works, you can modify it to your needs.
If it fails, post all the failing info and the line that is in error,
not just the line number or the whole script (keep it small but complete).
___
Perl-Win32-Web mailing list
Perl-Win32-Web@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: HTTP request arguments/content

2007-01-30 Thread Marijn Pessers
Hello Bill,

Thanks for your response, but something still is wrong.

When I try your code (I checked and as far as I can see I adapted mine to
your example) I get this error message:

Can't call method "content" on an undefined value at
./neopost_fetch_machinetype_new.pl line 98,  line 1.

FILEHANLDE is the file I get the value from...

The code in the row that goes wrong is the following:
return $res->content;

I printed $res and got this result:
HTTP::Response=HASH(0x858bb9c)

I think I can't call content directly from the $res. What must change?

Kind regards, 

Marijn


-Original Message-
From: Bill Luebkert [mailto:[EMAIL PROTECTED] 
Sent: maandag 29 januari 2007 22:55
To: Marijn Pessers
Cc: Perl-Win32-Web@listserv.ActiveState.com
Subject: Re: HTTP request arguments/content

Marijn Pessers wrote:
> Hello,
> 
>  
> 
> I have been trying to open a html page in perl. It works but I can't 
> send the correct arguments (post values) with it to work.

Try this one:

use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);

sub get_page_http ($;$);

my $ua = LWP::UserAgent->new;
my $remote = 'localhost';   # fix me
my $path = '/somecgi.pl';   # fix me
my $leverancier_nr = 'stuff';
my $FMnummer = 'more stuff';
my $datastring = 'what goes here?';

my ($hdr, $ct) = get_page_http ($ua, $remote, $path, $leverancier_nr,
   $FMnummer, $datastring);
print "\nhdrs:\n$hdr\nct:\n$ct\n";
exit;

sub get_page_http ($;$) {
my $ua = shift;
my $remote = shift || 'localhost';
my $path = shift || '/';
my $leverancier_nr = shift;
my $FMnummer = shift;
my $datastring = shift || '';   # raw datastring for ?

# print "get_page: http:$remote$path ('$datastring')\n";

my $url = "http://$remote$path";;
my $req = POST $url, Content => [
 'submit_waarde' => '', 'page' => 'zks1', 'submit_waarde' => '',
 'leverancier_nr' => $leverancier_nr, 'FMnummer' => $FMnummer ];

for (1 .. 2) {
my $res = $ua->request($req);
if ($res->is_error) {
sleep 1;# wait a sec and try again
next;
}
if (wantarray) {
return ($res->headers_as_string, $res->content);
} else {
return $res->content;
}
}

# failed return null string(s)

if (wantarray) {
return ('', '');
} else {
return '';
}

}

__END__

__ NOD32 2017 (20070129) Information __

This message was checked by NOD32 antivirus system.
http://www.eset.com


___
Perl-Win32-Web mailing list
Perl-Win32-Web@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: HTTP request arguments/content

2007-01-29 Thread Bill Luebkert
Marijn Pessers wrote:
> Hello,
> 
>  
> 
> I have been trying to open a html page in perl. It works but I can’t 
> send the correct arguments (post values) with it to work.

Try this one:

use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);

sub get_page_http ($;$);

my $ua = LWP::UserAgent->new;
my $remote = 'localhost';   # fix me
my $path = '/somecgi.pl';   # fix me
my $leverancier_nr = 'stuff';
my $FMnummer = 'more stuff';
my $datastring = 'what goes here?';

my ($hdr, $ct) = get_page_http ($ua, $remote, $path, $leverancier_nr,
   $FMnummer, $datastring);
print "\nhdrs:\n$hdr\nct:\n$ct\n";
exit;

sub get_page_http ($;$) {
my $ua = shift;
my $remote = shift || 'localhost';
my $path = shift || '/';
my $leverancier_nr = shift;
my $FMnummer = shift;
my $datastring = shift || '';   # raw datastring for ?

# print "get_page: http:$remote$path ('$datastring')\n";

my $url = "http://$remote$path";;
my $req = POST $url, Content => [
 'submit_waarde' => '', 'page' => 'zks1', 'submit_waarde' => '',
 'leverancier_nr' => $leverancier_nr, 'FMnummer' => $FMnummer ];

for (1 .. 2) {
my $res = $ua->request($req);
if ($res->is_error) {
sleep 1;# wait a sec and try again
next;
}
if (wantarray) {
return ($res->headers_as_string, $res->content);
} else {
return $res->content;
}
}

# failed return null string(s)

if (wantarray) {
return ('', '');
} else {
return '';
}

}

__END__
___
Perl-Win32-Web mailing list
Perl-Win32-Web@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs