开发者

http 403 when accessing an url in perl

I want to access a webpage but I'm getting 40开发者_开发问答3, failure for THIS url. But when I access using Firefox it shows HTTP 200 OK.

This is the code I'm using to access it:

    my $agent = LWP::UserAgent->new(env_proxy => 1,keep_alive => 1, timeout => 30, agent => "Mozilla/5.0");
         my $header = HTTP::Request->new(GET => $link);

         my $request = HTTP::Request->new('GET', $link, $header);

          my $response = $agent->request($request);

          if ($response->is_success){
........


Your code worked fine on my system accessing one of my own sites. I would guess that the website you hitting is allergic to automated requests. The user agent you are using is very minimal, and they may reject anything that does not look real. Here is a more genuine agent:

"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.71 Safari/534.24"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜