NET::HTTP, LWP and XML - pulling my hair out!!!

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

  1. #1

    Default NET::HTTP, LWP and XML - pulling my hair out!!!

    Hello

    I've been trying to read an http request of an XML formatted document.
    I am having no luck!

    Here's the scenario (my scripts are posted at end of message):

    my $req = HTTP::Request->new(GET => $url);
    my $res = $ua->simple_request($req);

    return in the $res variable the value:

    "HTTP::Response=HASH(0x27c4f0c)"

    which means nothing to me!

    If I was GETting an html file, I could grab the content body with this
    line of code:

    my $response = $res->content;

    but instead, I get an empty string in the $response variable, leading
    me to believe that $res->content does not recognize XML.

    BTW, I haven't yet tried (I'm stubborn) this or similar:

    $xp = XML::XPath->new(xml => $res->content);


    *
    *
    *
    MY QUESTION: Can't I just get a raw string of text through an http
    request regardless of it being an HTML or XML formatted document?
    *
    *
    *

    THANKS!!!!


    # first one
    > > use Net::HTTP;
    > >
    > > my $s = Net::HTTP->new(Host => "$host") || die $@;
    > > $s->write_request(GET => "$query",
    > > 'User-Agent' => "Mozilla/5.0");
    > > my($code, $mess, %h) = $s->read_response_headers;
    > >
    > >
    > > while (1) {
    > > my $buf;> >
    > > my $n = $s->read_entity_body($buf, 1024);
    > > die "read failed: $!" unless defined $n;
    > > last unless $n;
    > > print $buf;
    > > }
    > >
    > > # 2
    > >
    > > use LWP::UserAgent;
    > >
    > > my $ua = new LWP::UserAgent;
    > >
    > > my $req = HTTP::Request->new(GET => $url);
    > > my $res = $ua->simple_request($req);
    > > my $response = $res->content;
    > >
    > > print $response;
    > >
    north Guest

  2. Similar Questions and Discussions

    1. tearing my hair out...
      This is probably something simple, but, I cannot for the life of me figure this out - please look at http://www.kevincrowepottery.com/firing.htm ...
    2. 2004 preloading - pulling hair out, only one left
      I have acquired a preloader for MX 2004 that works GREAT with a large image file. I tried to replace it with several frames of my own animation....
    3. Pulling my hair out!! Text on a path??
      I can always get that far, but how can I add the text to the inside of the path instead of the outside of the path? Best regards, Jip
    4. Please someone's GOT to help me - I am pulling my hair out!
      Hi everyone and anyone I am running Apache2, Mysql and php on my P4. When I run a simple php script that inserts new data into a database...
    5. How do I POST variables to a php script ON A LOCALSERVER - I AM PULLING MY HAIR OUT
      Hi everyone and anyone I am running Apache2, Mysql and php on my P4. When I run a simple php script that inserts new data into a database...
  3. #2

    Default Re: NET::HTTP, LWP and XML - pulling my hair out!!!

    Thanks guys, the code actually works fine. There was a bug in the
    program calling this script.


    cp <cpryce@pryce.net> wrote in message news:<310720031341366149%cpryce@pryce.net>...
    > In article <1b06f702.0307301731.ef010bc@posting.google.com> , north
    > <wiseup@canada.com> wrote:
    >
    > > > > # 2
    > > > >
    > > > > use LWP::UserAgent;
    > > > >
    > > > > my $ua = new LWP::UserAgent;
    > > > >
    > > > > my $req = HTTP::Request->new(GET => $url);
    > > > > my $res = $ua->simple_request($req);
    > > > > my $response = $res->content;
    > > > >
    > > > > print $response;
    > > > >
    >
    > I use this code. Try setting your $req->content_type() to 'text/xml',
    > and I'd stay away from simple_request. YMMV.
    >
    > use LWP::UserAgent;
    > use XML::Simple;
    >
    > my $ua = LWP::UserAgent->new( $ua_string );
    > my $req = HTTP::Request->new( POST => $url ); # Or GET=>$url
    > $req->content_type('text/xml');
    >
    > my $res = $ua->request( $req );
    >
    > if ( $res->is_success() ) {
    > # parse $res->content
    > }
    > else {
    > # throw an error message
    > }
    north 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