<?xml version="1.0" encoding="windows-1252"?>
<node id="1010955" title="URI::Fetch and LWP::UserAgent strangeness" created="2012-12-30 14:20:13" updated="2012-12-30 14:20:13">
<type id="115">
perlquestion</type>
<author id="415035">
szabgab</author>
<data>
<field name="doctext">
In the following example I keep getting "1: Forbidden" as output, but I don't see what is the real difference between the two calls. Can anyone see it? UIR::Fetch is at 0.09 and 
LWP::UserAgent is 6.04.

&lt;code&gt;
use strict;
use warnings;

use URI::Fetch;
use LWP::UserAgent;

my $source = 'http://thorsen.pm/atom';

my $res2 = URI::Fetch-&gt;fetch($source);
print '2: ' . URI::Fetch-&gt;errstr if not $res2;

my $ua  = LWP::UserAgent-&gt;new;
$ua-&gt;env_proxy; # force allowing of proxies
my $res1 = URI::Fetch-&gt;fetch($source, UserAgent =&gt; $ua);
print '1: ' . URI::Fetch-&gt;errstr if not $res1;
&lt;/code&gt;

If I change the $source to be  http://code.foo.no/feed then I keep getting "1: Bad Behavior".
&lt;p&gt;
Very strange. Other URLs I tried work well.
&lt;p&gt;
And just to explain why is this important, I am using XML::Feed to fetch and parse RSS and Atom feeds, and XML::Feed uses the code as it is written in the problematic case. So currently these two feeds keep giving me error.

&lt;h2&gt;Update&lt;/h2&gt;

I found it. I think. Earlier, when I stepped through the code with the debugger I missed it, but now I saw the difference. The LWP::UserAgent created by URI::Fetch identifies itself as "URI::Fetch/0.09"  while the default UserAgent I passed to the fetch method had the default identification string 'libwww-perl/6.04'.
&lt;p&gt;
Apparently those two servers refuse to serve to the well known Perl user agent. Probably in an attempt to fend off certain bots.
&lt;p&gt;
So I have to change the UserAgent in XML::Feed.
</field>
</data>
</node>
