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
use LWP::UserAgent; use HTTP::Request; use HTTP::Cookies; my $url = shift || 'http://192.168.2.10/data/ajax.txt?CAN=1&HASH=00100403&TYPE=1'; # setup your browser my $ua = LWP::UserAgent->new(keep_alive => 1, timeout => 300); # what kind of browser you are $ua->agent("Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3a) Gecko/20021207 Phoenix/0.5"); # a place to store cookies, if needed $ua->cookie_jar( HTTP::Cookies->new(file => "perlcookies.dat", autosave => 1) ); # now build a request my $request = HTTP::Request->new( GET => $url ); # set credentials $request->authorization_basic('BN','PW'); # run browser my $response = $ua->request($request); # and check response printf $response->content();
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"><html><head><meta name="generator" content="HTML Tidy for Windows (vers 1st April 2002), see www.w3.org"><title>401 Unauthorized</title></head><body><script type="text/javascript">function getURL(){return document.URL();}</script><h1>Unauthorized</h1><p>Authorization for the requested URL: <b><script type="text/javascript">document.write(document.URL);</script></b> required.</p><hr><address>emBetter web server 2.0</address></body></html>
2013-04-01T12:33:07 GwenDragonCrosspost auf http://forum.fhem.de/index.php?t=msg&th=12034&goto...
$ua->credentials($host . $port, $realm, $username, $password);