in reply to Re: LWP::UserAgent Wrongly Uses HTTP/1.1
in thread LWP::UserAgent Wrongly Uses HTTP/1.1

HOORAY!!!!

Many, many thanks my Anonymous friend--you get the cookie today. That does the trick, *and* allows me to use both HTTP/1.0 and HTTP/1.1 in the same script. For those interested, you need to do something like this to use both in one script:

use LWP; require LWP::Protocol::http; require LWP::Protocol::http10; #do an HTTP/1.0 request LWP::Protocol::implementor('http', 'LWP::Protocol::http10'); my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new(GET => "$url"); my $res = $ua->request($req); #now do an HTTP/1.1 request LWP::Protocol::implementor('http', 'LWP::Protocol::http'); my $ua2 = LWP::UserAgent->new; my $req2 = HTTP::Request->new(GET => "$url"); my $res2 = $ua->request($req2);

Great stuff--thanks again!

Replies are listed 'Best First'.
Re: Re: Re: LWP::UserAgent Wrongly Uses HTTP/1.1
by edan (Curate) on Nov 20, 2003 at 15:13 UTC

    Just a caveat, since your code makes me think you misunderstand just a wee bit. The implementor matters at the time you make the request, not when you create the user agent object. So in your example, if you add the line

    $ua->request($req);

    at the end there, I think you'll find that it makes an HTTP/1.1 request, not HTTP/1.0 like your code leads me to believe you might be thinking (your code suggests to me that you think you have now an 'HTTP/1.0 user agent' ($ua) and an 'HTTP/1.1 user agent' ($ua2) and you can just alternate UAs to alternate which protocol to use). See the code I suggested above in my update.

    At least, this is the behavior I found when I tested with my version, which may be different from yours.

    HTH

    --
    3dan

      True--I posed the code the way I did because my actual script does create two seperate agents/requests (for other non-related organizational reasons). It probably would have been clearer for other folks had I done it with one agent/request as you suggest. You are correct in saying that it matters at the time of the request though.
Re: Re: Re: LWP::UserAgent Wrongly Uses HTTP/1.1
by Anonymous Monk on Nov 20, 2003 at 14:47 UTC
    And of course, I should also thank the rest of you who offered help--the awesome community support perl has is part of what makes it so great.