I am currently trying to make a Perl program to use an HTTPS website. Now I can access the website fine. However, the second I try to submit any kind of form (even just click_button), then it leads to a 401 unauthorized question.

What could I be doing wrong? How come my credentials work fine when going to a page on the site, but the second I try any kind of form it leads to an error? Just to be clear I am a newbie at web-using programs so my coding might be sad. In this example, all I'm trying to do is click a "if you agree, click here" button to get past a disclaimer (get redirected here). Sorry for editing out the website, but it's not a public site.

Update - I tried just a simple follow_link, with the same unauthorized results. Just to be clear, my credentials are allowing me to go to a protected page (in a get(URL) statment). It's not letting me click on a link/form to go to a different page (even pages that work if I just use a get(URL) statement). I don't know if this will help, but without the MIME::Base64 use, I can't even 'jump' to a page. Still working on it.

#!usr/bin/perl use strict; use warnings; require LWP::UserAgent; require HTTP::Request::Common; require HTTP::Response; use HTML::Form; use WWW::Mechanize; use MIME::Base64; my $username = 'username'; my $password = 'password'; my @args = ( Authorization => "Basic " . MIME::Base64::encode( $username . ':' . $password )); my $mech = WWW::Mechanize->new(); # I can remove the realm/host without affecting the 200 -> 401 occuran +ce $mech->credentials( 'www.edited.com:443', 'Title', $username, $passw +ord ); # enabling cookies, I'm not sure if I even need this part use HTTP::Cookies; $mech->cookie_jar( HTTP::Cookies->new( 'file' => '~/Desktop/programming/cookies.lwp', # where to read/write cookies 'autosave' => 1, # save it to disk when done )); # the site my $url = "https://www.edited.com/disclaimer.cgi"; $mech -> get ($url, @args); # HTML prints normally print $mech->content; # then I just want to click the button B1 $mech->click_button(name => 'B1'); # just in case it was a delay issue sleep(5); # then I get a 401 error print $mech->status(), "\n";
Thank you.

In reply to HTTPS WWW::Mechanize Form Problems by LE500

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.