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

Consider my code snippet:
use strict; use warnings; use HTTP::Cookies; use WWW::Mechanize; use LWP::Debug qw(+); my $mech = WWW::Mechanize->new(); $mech->agent_alias('Windows IE 6'); $mech->cookie_jar(HTTP::Cookies->new(autosave => 1)); $mech->add_header('UID' => 'phil', 'cn' => 'CN', 'id' => '777'); my $response = $mech->get('https://www.example.com'); die "Error at https://www.example.com\n", $response->status_line, "\n Aborting" unless $response->is_success; $response = $mech->response; for my $key ($response->header_field_names()) { print "response[$key] = ", $response->header($key), "\n"; }
I am trying to add new headers into the HTTP headers and yet I do not see 'UID' nor 'cn' nor 'id' whenever I list all of the returned headers even though I added them. What might I be doing wrong, and thus, how can I fix it so that these three addtitional fields are added to the HTTP headers? Thanks Phil

Replies are listed 'Best First'.
Re: How do I add headers using WWW::Mechanize?
by NetWallah (Canon) on Feb 19, 2008 at 21:46 UTC
    You seem to be wanting the web server to return your Request headers as a part of the response headers.
    Web servers will not normally do that (unless programmed specifically).

    For details, see the w3 rfc related to http headers.

         "As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom

      Ultimately what I am trying to do is to go to a particular website, say

      1) https://www.example.com/main/index.html

      But you cannot go to that site unless you are authenticated via

      2) https://www.example.com/registration/login.html
      3) https://www.example.com/registration/login_2.html
      4) Siteminder https://www.example.com/login/login.fcc

      If not authenticated when you get to 1) you are automatically redirected to 2). You fill out a form with username and password to get to 3) which consists of a form with hidden values of your username and password which automatically submit to 4), which does the authentication and then once authenticated your username is passed as a header value all the way back to 1).

        I have not attempted automated siteminder logon.

        Perhaps this article on logon auomation (obtained via Google search) will help.

             "As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom