Ask a Question related to PERL Modules, Design and Development.
-
north #1
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
-
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 ... -
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.... -
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 -
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... -
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... -
north #2
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



Reply With Quote

