LWP, Post, return data ?
am 12.10.2007 04:26:50 von unknownPost removed (X-No-Archive: yes)
Post removed (X-No-Archive: yes)
On Oct 11, 10:26 pm, still me
> I am trying to write a cgi that calls (POSTs to) another cgi. The
> second cgi returns a web page (HTML). I can't seem to figure out how
> to get to the data that the second cgi sends back. The cgi runs, the
> POST works, but i don't know how to access the return output from the
> second cgi (so I can pass it back to the browser that made the initial
> call).
>
> Here's the (very trimmed) code of the first program:
>
> #!/usr/bin/perl -w
> use strict;
> use CGI qw(:all);
> use CGI::Carp qw(fatalsToBrowser);
> use LWP;
> my $browser = LWP::UserAgent->new;
> my $url = 'http://www.example.com/cgi-bin/second.pl';
> my $response = $browser->post( $url,
> [ 'ed' => '001',
> 'test' => 'it worked',
> ]
> );
>
> # and right here I want to forward the data to the calling browser
LWP::UserAgent::post() returns an HTTP::Response object.
http://search.cpan.org/~gaas/libwww-perl-5.808/lib/HTTP/Resp onse.pm
$response = $ua->request($request)
if ($response->is_success) {
print $response->content;
}
else {
print STDERR $response->status_line, "\n";
}
Paul Lalli
Post removed (X-No-Archive: yes)
Post removed (X-No-Archive: yes)
On Oct 12, 12:00 am, still me
> On Thu, 11 Oct 2007 19:38:27 -0700, Paul Lalli
> wrote:
> >LWP::UserAgent::post() returns an HTTP::Response object.
>
> >http://search.cpan.org/~gaas/libwww-perl-5.808/lib/HTTP/Res ponse.pm
> I need a little more help. I also need to access the return headers
> that are sent back from the called cgi. I read this:
>
> http://search.cpan.org/~gaas/libwww-perl-5.808/lib/HTTP/Head ers.pm
>
> And I think I need to access this: $h->as_string( $eol )
>
> But I am having trouble making the logical jump as to how the code
> would actually look. It's clear enough when I want to create a new
> header object, but how do I get the return values from
> the "$response = $ua->request($request)" to populate the header
> object? Some detailed code would be very helpful.
Again, from that same URL as above:
"HTTP::Response is a subclass of HTTP::Message and therefore inherits
its methods."
Therefore, we now look at: http://search.cpan.org/~gaas/libwww-perl-5.808/lib/HTTP/Mess age.pm
which shows us some available methods, such as:
$mess->headers
Returns the embedded HTTP::Headers object.
$mess->headers_as_string
$mess->headers_as_string( $eol )
Call the as_string() method for the headers in the message.
This will be the same as
$mess->headers->as_string
but it will make your program a whole character shorter :-)
Paul Lalli
On Oct 11, 9:00 pm, still me
> On Thu, 11 Oct 2007 19:38:27 -0700, Paul Lalli
> wrote:
>
> ...
> >LWP::UserAgent::post() returns an HTTP::Response object.
>
> >http://search.cpan.org/~gaas/libwww-perl-5.808/lib/HTTP/Res ponse.pm
>
> > $response = $ua->request($request)
> > if ($response->is_success) {
> > print $response->content;
> > }
> > else {
> > print STDERR $response->status_line, "\n";
> > }
>
> >Paul Lalli
>
> I need a little more help. I also need to access the return headers
> that are sent back from the called cgi. I read this:
>
> http://search.cpan.org/~gaas/libwww-perl-5.808/lib/HTTP/Head ers.pm
>
> And I think I need to access this: $h->as_string( $eol )
>
> But I am having trouble making the logical jump as to how the code
> would actually look. It's clear enough when I want to create a new
> header object, but how do I get the return values from the "$response
> = $ua->request($request)" to populate the header object? Some detailed
> code would be very helpful.
>
print $response->headers_as_string;
* or, to pull a specific header:
eg, print $response->header("Client-Peer")
--
Charles DeRykus
Post removed (X-No-Archive: yes)