http://qs321.pair.com?node_id=66999

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

I was wondering if anyone knows how to send a HTTP::Header with a redirect or a hyperlink? Please include code if you got one; thanks.


$h = new HTTP::Headers
blah blah => "blah blah";
$url = blah blah;
print "Location: $url, $h";
something like above "which i KNOW IS WRONG"
Adam
  • Comment on http::header, redirect, hyperlink send with location

Replies are listed 'Best First'.
Re: http::header, redirect, hyperlink send with location
by Anonymous Monk on Mar 25, 2001 at 14:42 UTC
    HTTP::Headers is for http requests, but redirects are for http responses, so I'm not sure if you're trying to make a request or respond to one. If you are responding to one, you can just print each header on a seperate line before the blank line terminating the header:
    print "CustomHeader: CustomValue\n"; print "Location: $url\n\n";
Re: http::header, redirect, hyperlink send with location
by sutch (Curate) on Mar 25, 2001 at 20:55 UTC
    I've never used HTTP::Headers, instead I use HTTP::Response or CGI. Doing it with CGI is easy:

    use CGI; my $q = new CGI; print $q->redirect(-uri=>'http://blah.com/blah');
    Which returns:

    Status: 302 Moved location: http://blah.com/blah
Re: http::header, redirect, hyperlink send with location
by $CBAS (Scribe) on Mar 25, 2001 at 14:28 UTC
    I think this should do it:
    $url = "http://www.perlmonks.org/"; print "URI: $url\n\n";
Re: http::header, redirect, hyperlink send with location
by BMaximus (Chaplain) on Mar 25, 2001 at 16:59 UTC
    I looked at the man page for HTTP::headers and it isn't realy clear as to how to use it. I'm used to mod_perl and not doing cgi without it. My best guess:
    my $h = new HTTP::Headers Content_Type => 'text/html', Location => 'http://foo.com'; print $h->as_string,"\n\n";
    Since I'm assuming that your stuff is being handled by the server you only need to output a partial header. The two newlines will separate the content of the page as required. This is the best that I can do since I realy don't know what your trying to do except use HTTP::headers to do what it does best. Read the man page on how to use it. I hope I've given you a nudge in the right direction.

    BMaximus