LWP Logging or the such..

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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...
    5. 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...
  3. #2

    Default 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

  4. #3

    Default 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

  5. #4

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139