Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Problem with HEAD.. but I think can be related with DNS

by angeloulivieri (Novice)
on Mar 20, 2014 at 16:32 UTC ( #1079100=perlquestion: print w/replies, xml ) Need Help??

angeloulivieri has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, this code on my computer is not working
use LWP::UserAgent; use HTTP::Headers; my $link = " +e/knowledgebase/complete/reldate.txt"; simple_get($link); sub simple_get { my $url = shift; use HTTP::Request; use LWP::UserAgent; my $ua = new LWP::UserAgent; my $request = HTTP::Request->new(GET => $url); my $response = $ua->request($request); my $error = 1 unless ($response->is_success); if ($error){ print "There is an error\n"; }else{ print "OK!\n"; } }
It returns: There is an error Even if I know that the link is correct, I told to the mantainers of but they said that for them it's fine. So I was thinking that maybe a problem in my DNS can give this 404 error that I get. Is there a way to change the DNS to access a link using some PERL native functions?

Thank you all


Replies are listed 'Best First'.
Re: Problem with HEAD.. but I think can be related with DNS
by Your Mother (Archbishop) on Mar 20, 2014 at 17:26 UTC

    Works for me. Note you are not doing a HEAD request, but a GET. I changed your sub a little (moved the use statements to the top of the script).

    sub simple_get { my $url = shift; my $ua = LWP::UserAgent->new; my $request = HTTP::Request->new(GET => $url); my $response = $ua->request($request); warn "ERROR!" unless $response->is_success; print $response->as_string; }

    And this is the output–

    200 OK Server: Welcome to UniProt FTP service. Content-Length: 151 Content-Type: text/plain Last-Modified: Wed, 19 Mar 2014 14:00:00 GMT Client-Date: Thu, 20 Mar 2014 17:25:38 GMT Client-Request-Num: 1 UniProt Knowledgebase Release 2014_03 consists of: UniProtKB/Swiss-Prot Release 2014_03 of 19-Mar-2014 UniProtKB/TrEMBL Release 2014_03 of 19-Mar-2014
      Aargh!! This is mine with you code:
      ERROR! at line 85. 404 File 'reldate.txt' not found Client-Date: Thu, 20 Mar 2014 16:50:25 GMT
      Something is not working for me but I cannot find out what... I have two parts of my code: - in the first I simply check for the link if it is correct - in the second I download the file corresponding to this link In the second I adjusted the code by doing a double attempt: one using LWP (HTTP::Request->new (GET => $link)) and another using File::Fetch. With File::Fetch function the download is working but not with HTTP::Request
        Does anyone has an idea of why this is happening?
Re: Problem with HEAD.. but I think can be related with DNS
by Corion (Patriarch) on Mar 20, 2014 at 16:43 UTC

    If you get a 404, then DNS is not the problem.

    If you can resolve the name to its IP address then DNS is not the problem.

    What steps have you taken to eliminate DNS as the problem?

      There was a typo in the URL.
      Yes.. you are right. If the server gives 404 the IP address is resolved. But what can be the problem otherwise? Do you tried this code? Is it working for you?

        At least I get no 404 error for the URL when I paste it into my browser.

        Maybe you want to print out more stuff while your program runs, and use LWP::Debug to see what actually happens? If the server is giving you a 404 but not other people, maybe the server administrators have banned your IP address, your user agent or some other attribute associated with you.

Re: Problem with HEAD.. but I think can be related with DNS
by hazylife (Monk) on Mar 20, 2014 at 16:37 UTC

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1079100]
Approved by Old_Gray_Bear
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2023-03-31 06:12 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (74 votes). Check out past polls.