in reply to beyond LWP return code
Tested and looked into the code for LWP::UserAgent. You are right, it does dictate the return code.
I agree with you, this is wrong, as it quietly modifies the true meaning of the response code.
Strictly speaking, in case that the host cannot be contacted or there is no response, undef shall be returned instead of a HTTP::Response object. A seperate field shall be used to give the reason why undef is returned.
But LWP::UserAgent does give you a hint in its _msg field, which you can use:Under the above case, you get:require LWP::UserAgent; use Data::Dumper; use strict; use warnings; my $res = LWP::UserAgent->new()->get('http://www.hopingthereisnosuchth +ing.com/ah'); print "return code = $res->{'_rc'}\n"; print "msg = $res->{'_msg'}\n";
return code = 500 msg = Can't connect to www.hopingthereisnosuchthing.com:80 (Bad hostna +me 'www.hopingthereisnosuchthing.com')
By the way, it is better not to use the internal field names like _rc and _msg. HTTP::Response has two methods defined to return those two fields, so just call code() and message().
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: beyond LWP return code
by Anonymous Monk on Oct 20, 2003 at 00:34 UTC |