1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
package Hotfile; # Perl->Hotfile API use LWP::UserAgent; our $HFA_VERSION = 0.1; # Perlmodul Version our $HFA_WHO = "Hotfile-PerlAPI/$HFA_VERSION"; # UserAgent-Name sub new() { # Die $->new Funktion my $class = shift; return bless {}, $class; } sub link_status(){ my $url = shift; my $browser = new LWP::UserAgent; $browser ->agent($HFA_WHO); my $resp = $browser->get("http://api.hotfile.com/?action=checklinks&links=$url&fields=status"); my $status = $resp->decoded_content(); return $status; } 1;
Guest KCobainMüsstest du?Als status müsste ich entweder 0, 1 oder 2 zurück bekommen - aber ich kriege garkeinen wert zurück. Wo liegt der fehler?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
package Hotfile; # Perl->Hotfile API use strict; use warnings; use LWP::UserAgent; our $HFA_VERSION = 0.1; # Perlmodul Version our $HFA_WHO = "Hotfile-PerlAPI/$HFA_VERSION"; # UserAgent-Name sub new() { my $class = shift; return bless {}, $class; } sub link_status($){ my $url = shift; my $browser = new LWP::UserAgent; $browser ->agent($HFA_WHO); my $resp = $browser->get("http://api.hotfile.com/?action=checklinks&links=$url&fields=status"); my $status = $resp->decoded_content(); return $status; } 1;
1 2 3 4 5 6 7 8
#!/usr/bin/perl use strict; use warnings; use lib '.'; use Hotfile; my $a = new Hotfile; my $b = $a->link_status("http://hotfile.com/dl/131350300/aec8c02/test.txt.html"); print $b;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
package Hotfile; # Perl->Hotfile API use strict; use warnings; use LWP::UserAgent; our $HFA_VERSION = 0.1; # Perlmodul Version our $HFA_WHO = "Hotfile-PerlAPI/$HFA_VERSION"; # UserAgent-Name sub new { my $class = shift; my $self={}; $self->{_LWP}=LWP::UserAgent->new(); $self->{_content}=undef; $self->{_LWP}->agent($HFA_WHO); return bless $self, $class; } sub LWP { return $_[0]->{_LWP}; } sub content { return $_[0]->{_content} || ''; } sub _set_content { my $self=shift; my $content=shift; $self->{_content}=$content; } sub link_status { my $self = shift; my $url = shift || ''; my $browser = $self->LWP(); my $resp = $browser->get("http://api.hotfile.com/?action=checklinks&links=$url&fields=status"); my $status = $resp->is_success(); $self->_set_content($status?$resp->decoded_content():undef); return $status; } 1;