Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > LWP, Post, return data ?

Reply
Thread Tools

LWP, Post, return data ?

 
 
still me
Guest
Posts: n/a
 
      10-12-2007
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

Thanks
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      10-12-2007
On Oct 11, 10:26 pm, still me <(E-Mail Removed)> wrote:
> 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:ost() returns an HTTP::Response object.

http://search.cpan.org/~gaas/libwww-...TP/Response.pm

$response = $ua->request($request)
if ($response->is_success) {
print $response->content;
}
else {
print STDERR $response->status_line, "\n";
}

Paul Lalli

 
Reply With Quote
 
 
 
 
still me
Guest
Posts: n/a
 
      10-12-2007
On Thu, 11 Oct 2007 19:38:27 -0700, Paul Lalli <(E-Mail Removed)>
wrote:

> $response = $ua->request($request)
> if ($response->is_success) {
> print $response->content;
> }
> else {
> print STDERR $response->status_line, "\n";
> }



Thanks. I tried something like that multiple ways but it didn't work.
But, since you insisted, I went back to it one more time. Turned out
is was an error in terms of what was coming back from the called
program. It's always sumthin!
 
Reply With Quote
 
still me
Guest
Posts: n/a
 
      10-12-2007
On Thu, 11 Oct 2007 19:38:27 -0700, Paul Lalli <(E-Mail Removed)>
wrote:

>> #!/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:ost() returns an HTTP::Response object.
>
>http://search.cpan.org/~gaas/libwww-...TP/Response.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-...TTP/Headers.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.

Thanks,



 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      10-12-2007
On Oct 12, 12:00 am, still me <(E-Mail Removed)> wrote:
> On Thu, 11 Oct 2007 19:38:27 -0700, Paul Lalli <(E-Mail Removed)>
> wrote:


> >LWP::UserAgent:ost() returns an HTTP::Response object.

>
> >http://search.cpan.org/~gaas/libwww-...TP/Response.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-...TTP/Headers.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-...TTP/Message.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

 
Reply With Quote
 
comp.llang.perl.moderated
Guest
Posts: n/a
 
      10-12-2007
On Oct 11, 9:00 pm, still me <(E-Mail Removed)> wrote:
> On Thu, 11 Oct 2007 19:38:27 -0700, Paul Lalli <(E-Mail Removed)>
> wrote:
>
> ...


> >LWP::UserAgent:ost() returns an HTTP::Response object.

>
> >http://search.cpan.org/~gaas/libwww-...TP/Response.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-...TTP/Headers.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

 
Reply With Quote
 
still me
Guest
Posts: n/a
 
      10-13-2007
On Fri, 12 Oct 2007 05:22:27 -0700, Paul Lalli <(E-Mail Removed)>
wrote:


>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-...TTP/Message.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



Thanks Paul. I was getting a bit confused amongst all the objects.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
difference between return &*i and return i; Ganesh Gella C++ 4 11-12-2004 04:28 PM
How do I return a return-code from main? wl Java 2 03-05-2004 05:15 PM
Data-access servlet does not return any data Nishi Bhonsle Java 0 12-05-2003 07:31 PM
Return a return value from Perl to Javascript PvdK Perl 0 07-24-2003 09:20 AM



Advertisments