I'll admit, I'm a bit iffy on the realm thing...
I'm assuming your D-link router does HTTP Basic authentication here. To be certain of the realm, use a web-browser to visit the page, and pay attention to the dialogue box that you get. With my browser, I get the string "Please enter username and password for "Realmname"..." — this gives you the realm name you should be using.

Here's my attempt at what you might want... untested, because I don't have access to a D-Link router, and I'm a bit too lazy to set up a webserver with HTTP Basic authentication.

#!/usr/bin/perl use warnings; use strict; use LWP::UserAgent; my $ua = LWP::UserAgent->new(); $ua->credentials("192.168.0.1","192.168.0.1","admin", "password"); my $response = $ua->get("http://192.168.0.1/st_devic.html"); die "Error while getting ", $response->request->uri, " -- ", $response->status_line, "\nAborting" unless $response->is_success; print $response->content, "\n";

3rd Update (yikes!): You want to use the server's location as the first argument to credentials. I missed the different IP addresses when I first read your code.


davis
It's not easy to juggle a pregnant wife and a troubled child, but somehow I managed to fit in eight hours of TV a day.

Update: Apparently I'm confusing Latex commands with HTML entities. Sigh


In reply to Re: Basic authentication with LWP::UserAgent by davis
in thread Basic authentication with LWP::UserAgent by abeal

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.