Thread Website aufruf (11 answers)
Opened by KCobain at 2011-10-03 14:24

topeg
 2011-10-03 21:17
#152836 #152836
User since
2006-07-10
2611 Artikel
BenutzerIn

user image
Der erste Parameter bei einer Methode ist das Objekt zu der die Methode gehört.

So kann man es machen:
Code (perl): (dl )
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;


Erzeuge das LWP-Objekt nur einmal, dann kannst du auch Logins etc. handhaben.

Der String in $url sollte kodiert werden, damit der Server nicht durcheinander kommt und Teil des Strings als Teil der Anfrage interpretiert.
Last edited: 2011-10-03 21:30:43 +0200 (CEST)

View full thread Website aufruf