For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > May 2006 > LWP debug









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author LWP debug
Luis

2006-05-02, 7:58 am

Hi,

the following code is part of a bigger script. I would like to know if
there is a way to print out or store into a file all the messages that
my script sends to the server, I mean, the full header and data parts
sent to the server, in order to debug my application.


----------------------------------------------------------------------

my $ua = LWP::UserAgent->new;
my $request = POST "$remote_host/webct/systemIntegrationApi.dowebct",
Content_Type => 'form-data',
Content => [ ACTION => $params{'ACTION'},
OPTION => $params{'OPTION'},
TIMESTAMP => $params{'TIMESTAMP'},
AUTH => $params{'AUTH'},
FILENAME => [ $params{'FILENAME'} ] ];

my $response = $ua->request($request);
my $content = $response->content();
if (!$content)
{
print "Connection to $remote_host failed\n";
}
else
{
print $content;
}

----------------------------------------------------------------------

Storing into a file is preferred over printing out to screen.

Thank you very much.
Best regards,
Luis A.
Peter Scott

2006-05-02, 6:58 pm

On Tue, 02 May 2006 13:06:56 +0200, luis wrote:
> the following code is part of a bigger script. I would like to know if
> there is a way to print out or store into a file all the messages that
> my script sends to the server, I mean, the full header and data parts
> sent to the server, in order to debug my application.


use LWP::Debug qw(+conns);

> my $ua = LWP::UserAgent->new;

[snip]
> Storing into a file is preferred over printing out to screen.


Internally it is hardwired to print to STDERR. You could override the
private method _log() that contains that code, but that would be rude.
Better to redirect STDERR before your LWP calls.

--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/

Luis

2006-05-03, 3:58 am

Peter Scott wrote:
> On Tue, 02 May 2006 13:06:56 +0200, luis wrote:
>
>
>
> use LWP::Debug qw(+conns);
>
>
>
> [snip]
>
>
>
> Internally it is hardwired to print to STDERR. You could override the
> private method _log() that contains that code, but that would be rude.
> Better to redirect STDERR before your LWP calls.
>


Thank you, Peter. That would be great if I knew where to read the STDERR
since I'm running my script from the command line in an out-of-the-box
CentOS linux installation. The only thing I got was outputting something
like:

# LWP::DebugFile logging to lwp_44585fc2_30a3.log
# Time now: {1146642370} = Wed May 3 09:46:10 2006
LWP::UserAgent::new: ()
LWP::MediaTypes::read_media_types: Reading media types from
/usr/lib/perl5/site_perl/5.8.0/LWP/media.types
LWP::MediaTypes::read_media_types: Reading media types from
/usr/lib/perl5/vendor_perl/5.8.0/LWP/media.types
LWP::UserAgent::request: ()
LWP::UserAgent::send_request: POST
http://localhost:8080/webct/systemI...tionApi.dowebct
LWP::UserAgent::_need_proxy: Not proxied
LWP::Protocol::http::request: ()
LWP::Protocol::collect: read 33 bytes
LWP::Protocol::collect: read 44 bytes
LWP::UserAgent::request: Simple response: OK


using LWP::DebugFile but I was expecting to get the full messages that
the script is sending to the server in the other side, something like:

POST /webct/systemIntegrationApi.dowebct HTTP/1.0
Content-length: 1253
Content-type: multipart/form-data;

boundary=WebCT_Enterprise_API_Boundary
--WebCT_Enterprise_API_Boundary
Content-Disposition: form-data; name="ACTION"

import
--WebCT_Enterprise_API_Boundary
Content-Disposition: form-data; name="OPTION"
........... etc.

Can I get this using LWP::Debug? If so, with which options? And even one
more question, where it the STDERR stored when the script is ran in
command mode?.

Sorry for so many questions.

Best regards,
Luis A. Martínez
Peter Scott

2006-05-03, 7:58 am

On Wed, 03 May 2006 10:16:05 +0200, luis wrote:
> Peter Scott wrote:
>
> Thank you, Peter. That would be great if I knew where to read the STDERR
> since I'm running my script from the command line in an out-of-the-box
> CentOS linux installation.[...]
>
> using LWP::DebugFile but I was expecting to get the full messages that
> the script is sending to the server in the other side, something like:
>


For reasons currently outside my comprehension, it appears that in order
to get the data you want you need to set the environment variable

PERL_LWP_USE_HTTP_10

to something true. I shall dig further.

--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/

Girish

2006-05-25, 3:58 am

Thank you for that post. That was exactly what *I* needed to debug
further my script interaction with a server. :-)

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com