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

Is there any way to get defaultpage of given website url by reading http header infomation as i get contents of that file,but i need file name.

iam using this code

#!usr/bin/perl use LWP::Simple; $doc = get 'http://indiaimage.nic.in'; print "$doc \n";

Hope you help me getting defaultfile name of website.

V.vrao

20040315 Edit by Corion: Added formatting

Replies are listed 'Best First'.
Re: defaultpage of website
by Abigail-II (Bishop) on Mar 15, 2004 at 09:45 UTC
    No, there isn't. Side stepping the fact your question isn't at all Perl related, it doesn't make any sense from an HTTP point of view either. A 'default page' is an HTTP server issue. Some servers might support it, others don't. There might not even be a 'default page'.

    Abigail

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: defaultpage of website
by borisz (Canon) on Mar 15, 2004 at 09:36 UTC
    No. You must guess.
    Boris
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: defaultpage of website
by Aristotle (Chancellor) on Mar 15, 2004 at 11:22 UTC
    So, after a lot of guessing by looking at the other replies, you seem to want to know whether there's a way to know that a server is configured to respond to http://example.com/ by serving the file also available under http://example.com/index.html? This is a server configuration issue (as my question's phrasing already says), and there is no way to detect or query this information from the client end, no.

    Makeshifts last the longest.

    A reply falls below the community's threshold of quality. You may see it by logging in.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: defaultpage of website
by wolfi (Scribe) on Mar 16, 2004 at 06:05 UTC

    i confess, i've never used LWP... but i do work around webdev and i can't figure out, what you're trying to do.

    lemme explain...
    A) many developers (who have a site) capture info from users - like 'user agents' (browsers, spiders/bots, etc), http-referers (to tell'em where the visitor is coming from), etc... if you're trying to get this info from a site you don't own or work on - it begs the question... why?

    unless of course, you're trying to hack it (in which case, i won't be answering that Q).

    B) regarding default pages - this is done in configuration files on the server. The administrator can put whatever they wish as the default. And if the site is dynamically generated (via a script - like perl), uses frames, redirection, etc... as anonymous monk above me said, it's quite possible the visitor may not know. (And if you're trying to get into someone's config file, ya might wanna have an attorney on retainer.)

    you could always glance at the html's source code... that might give an indication - but that isn't guaranteed, since the server can redirect someone at its whim. You can ask for page X and the server might decide to give you page Y. It's the server's choice - it's THEIR files.

    C) To try to get this back to perl, however... Assuming you're not nefarious and are running a server yourself - trying to get info from your visitors, there's a very easy way to do this -> Just use environmental variables.

    my $item1 = $ENV{PATH_INFO} my $item2 = $ENV{PATH_TRANSLATED} my $item3 = $ENV{HTTP_USER_AGENT} my $item4 = $ENV{HTTP_REFERER} etc...

    i'm not gonna list all the possible @ENV out there, but any html/cgi book should have'em listed. (We'll plug the CGI Programming with Perl by O'Reilly) Do note, however, that these variables are dependent upon the visitor's platform (browser, etc) and its configuration. One can't rely on this info completely, but it isn't bad for broad-based statisical info.

      He's trying to get information about servers, not information about the visitors of these servers.

      Makeshifts last the longest.

Re: defaultpage of website
by Anonymous Monk on Mar 15, 2004 at 18:55 UTC
    The "default page" is dependent on the server. My server may return "index.html"; yours may return "index.htm"; someone else's may generate the webpage on the fly from "index.pl"; and a fourth website may, based on the language requested, return "index.de". But as a client, you can't tell where the data is coming from; the server is not obligated to tell you. Why don't you read about the HTTP protocol? This is not a perl question.