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

Hi, I have a script that has been working for some web pages require digest authentication. However, I just came across a new webpage that it fails to work. The script is as shown below. The realm is "ty3.asia.dummy.com:8096" which contains ":". At first I suspect this breaks the code but after reading how Digest uses MD5, it doesn't seem to be the root cause. Appreciate if anyone can shred some light on this.

#!/usr/bin/perl -w use warnings; use strict; use LWP::UserAgent; use URI; my $username="admin"; my $password="admin"; my $realm = "ty3.asia.dummy.com:8096"; my $url=qw(http://ty3.asia.dummy.com:8096/application); my $u = URI->new($url); my $host = $u->host; my $port = $u->port; my $hostport = "$host:$port"; my $ua = LWP::UserAgent->new(keep_alive => 1); $ua->credentials($hostport,$realm,$username,$password); my $response = $ua->get($url); my $content = $response->content; print "$content";

The Wireshark header traffic capture of the problematic webpage is as shown below. Keep-live is gone in the "Connection" field of the second GET message. How to add it back?

GET /application HTTP/1.1 TE: deflate,gzip;q=0.3 Keep-Alive: 300 Connection: Keep-Alive, TE Host: ty3.asia.dummy.com:8096 User-Agent: libwww-perl/6.04 HTTP/1.1 401 Unauthorized Pragma: No-cache Cache-Control: no-cache Expires: Thu, 01 Jan 1970 09:00:00 JST WWW-Authenticate: Digest realm="ty3.asia.dummy.com:8096", qop="auth", +nonce="d7757e011940461afd9baf04d54b0858", opaque="481c532d006d5dfa105 +44ae8b0adbed2" Content-Type: text/html;charset=utf-8 Content-Length: 954 Date: Wed, 18 Apr 2012 03:44:49 GMT Server: Apache-Coyote/1.1 GET /application HTTP/1.1 TE: deflate,gzip;q=0.3 Connection: TE Authorization: Digest username="admin", realm="ty3.asia.dummy.com:8096 +", qop="auth", algorithm="MD5", uri="/application", nonce="d7757e0119 +40461afd9baf04d54b0858", nc="00000001", cnonce="4f8e38b1", response=" +b9d9cf87cb315f82b8bbd0cf4d68d175", opaque="481c532d006d5dfa10544ae8b0 +adbed2" Host: jty3.asia.dummy.com:8096 User-Agent: libwww-perl/6.04 HTTP/1.1 401 Unauthorized Pragma: No-cache Cache-Control: no-cache Expires: Thu, 01 Jan 1970 09:00:00 JST WWW-Authenticate: Digest realm="ty3.asia.dummy.com:8096", qop="auth", +nonce="d5dfe8c5a4f563bdbafdfe6fe1a29118", opaque="dfb683538f7c122c0c6 +1181a52919473" Content-Type: text/html;charset=utf-8 Content-Length: 954 Date: Wed, 18 Apr 2012 03:44:49 GMT Server: Apache-Coyote/1.1

Replies are listed 'Best First'.
Re: LWP not working with digest authentication
by ajinkyagadewar (Novice) on Apr 18, 2012 at 07:49 UTC

    Hi,

    I tried to hit the url in code but it doesn't work. As a preliminary check, you can look at headers that need to passed in request as the authentication mechanism is Digest MD5.

    Regards, Ajinkya

      Hi,

      Thanks for your help. The webpage is in a private network. It's actually a web admin page of a vendor product. The web page is provided by Apache Tomcat from What I can see but I think it's kind of a trim-down version of Tomcat(I'm a Tomcat newbie) and I don't see any config files for the Tomat server come with the Vendor product.

      Besides, I changed the domain suffix to asia.dummy.com when I posted the problem here :-)

      I'm trying to create a Perl script to get some information from the web page for the monitoring of the vendor product. The Perl script I used works for some other web pages using Digest authentication but not this one. I've spent hours trouble-shooting but still have no clue what goes wrong . . .

      The web page in question works fine with IE and curl. When I fire the command below, I can get the web page. But the Perl codes I use fail to work . . .

      curl --digest -u admin:admin "http://ty3.asia.dummy.com:8096:8096/application"

        typo in my last message. The curl command should be:

        curl --digest -u admin:admin "http://ty3.asia.dummy.com:8096/application"