Ask a Question related to PERL Beginners, Design and Development.
-
Martin #1
LWP Logging or the such..
Good Morning/Afternoon Everyone,
I have been reading up on LWP::UserAgent and HTTP::Request of the LWP
package. This is good stuff.
But I am still confused about a couple of things. Here is ther senario.
I have a file I want to download from
my server and I can do that with LWP. But what I'm confused on is One:
how do I save the file to a certain
directory once I have started the GET process; insted of it dumping to
stdout? The other part I am unclear on
is this: if the site does not contain the file I am looking to GET, then
I should receive the standard web response
of 'file does not exist' or other responses like 'forbidden', etc. I am
unclear how to 'log' these responses or redirect
them to a file for later examination insted of dumping to stdout.
Thus far I have a script that will do what I want it to do, but now I
need to understand how to save my file(s)
to disk insted of dumping to stdout, and logging the responses to a file
for review. Let me know if I have made myself unclear. I look forward to
hearing from
you all soon with your input and ideas.
Thank You,
~Martin
Martin Guest
-
FMS 3 logging
I have posted a message about logging earlier. Can anyone tell me how logging is done in FMS3? Why are the entries for a single instance broken... -
Logging in
Hello, I rent a dedicated server for my Web site. Last week, I downloaded a demo copy of Flash Communication Server and asked my Host company to... -
Logging Out
I am developing an application where users will subscribe to access to the website. I want to restrict logins such that a userid can be logged in... -
logging
Hi all , what's the common module that's used for logging ? i have looked into log4perl. But seems that not quite mature and doesn't support... -
Logging on to XP pro????
Help please!! I installed XP pro a longtime ago and I guess I rushed through the install. I have never had to log onto XP when I boot up, now I... -
Martin #2
Re: LWP Logging or the such..
Update::
I have figured out how to save to file ..
I have to open a file handle .. duh? yeah .. i know.
Okay, but I would still like suggestions on saving my http responses to
file .. like a log file
of what the script was trying to do on execute.
~Martin
Martin R Morales wrote:
Martin Guest
-
Rob #3
Re: LWP Logging or the such..
Martin R Morales wrote:
>
> I have figured out how to save to file ..
> I have to open a file handle .. duh? yeah .. i know.
> Okay, but I would still like suggestions on saving my http responses to
> file .. like a log file
> of what the script was trying to do on execute.[/ref]
Hi Martin.
There are a few different ways you could be using the LWP library.
I don't understand how you got the output 'dumping to STDOUT' in the
first place. Have you check out the LWP::UserAgent::mirror method?
As for logging, what you're likely to want to do is
print $request->as_string;
and
print $response->status_line
where $request and $response are and HTTP::Request object and
an HTTP::Response object, respectively. More than that I can't
help without knowing what you want and what you're tried.
HTH,
Rob
Rob Guest
-
R. #4
Re: LWP Logging or the such..
Martin R Morales wrote:
That is not exactly the question at this point, because the response received
does not constitute a file while in transit. When LWP::UserAgent receives a
response, it puts it into an HTTP::Response object This object provides te
method content() to get the returned html. The request method, though, does
provide a means to automatically store this data to file. The scond parameter
of request can be a string scalar, in which case the module uses this string as
the filename to save the data to. The specific directory that you want to store
this data in is just part of the filename.
Does LWP::UserAgent dump to STDOUT? I don't think so. The get and request
methods both return response objects, which the calling script can query and
print to STDOUT.
Like this:
Greetings! E:\d_drive\perlStuff>perl -MLWP::UserAgent
my $ua = LWP::UserAgent->new;
my $request = HTTP::Request->new('GET',
'http://www.isp.org/~some_user/missing_page.htm');
my $response = $ua->request($request);
print $response->content;
^Z
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>404 Not Found</TITLE>
</HEAD><BODY>
<H1>Not Found</H1>
The requested URL /~some_user/missing_page.htm was not found on this server.<P>
<HR>
<ADDRESS>Apache/1.3.26 Server at members.isp.org Port 80</ADDRESS>
</BODY></HTML>
HTH,
Joseph
R. Guest



Reply With Quote

