的表单验证。 NET 站点使用 Perl

Form authentication for . NET sites using Perl

我们是 Perl 脚本的新手,我们想通过 .NET 站点身份验证。 我们有一个特定于 Sharepoint 站点的现有身份验证代码,代码段如下:

my $ua = new LWP::UserAgent('keep_alive' => '1');
print "$url \n";
$ua->credentials("$uname", "$pwd");
my $response =$ua->get($url);
my $cde = $response->code();

我们想要自定义代码,以便它可以专门用于 .NET 站点身份验证。我们使用了 WWW::Mechanize,请参见下面的代码片段:

my $mech = WWW::Mechanize->new();
$mech->cookie_jar(HTTP::Cookies->new());
$mech->get($url);
$mech->form_name('Login');
$mech->field("UserName", $username);
$mech->field("Password", $password);
$mech->click();

但是当程序是运行时,显示错误:"There is no form named 'Login' in sample.pl"。关于如何验证特定于 .NET 站点的表单的任何想法?

添加:HTML 表单代码片段...

<div id="loginArea">        
        <div id="loginMessage" class="groupMargin">Sign in with your account</div>
        <form method="post" id="Login" autocomplete="off" novalidate="novalidate" onkeypress="if (event &amp;&amp; event.keyCode
== 13) Login.submitLoginRequest();" action="">
            <div id="formsAuthenticationArea">
                <div id="userNameArea">
                    <input id="userNameInput" name="UserName" type="email" value="" tabindex="1" class="text fullWidth" spellcheck="false" placeholder="Username" autocomplete="off">     
                </div>
                <div id="passwordArea">
                     <input id="passwordInput" name="Password" type="password" tabindex="2" class="text fullWidth" placeholder="Password" autocomplete="off">                            

                </div>
                <div id="kmsiArea" style="display:none">
                    <input type="checkbox" name="Kmsi" id="kmsiInput" value="true" tabindex="3">
                    <label for="kmsiInput">Keep me signed in</label>
                </div>
                <div id="submissionArea" class="submitMargin">
                    <span id="submitButton" class="submit" tabindex="4" onkeypress="if (event &amp;&amp; event.keyCode == 32) Login.submitLoginRequest();" onclick="return Login.submitLoginRequest();">Sign in</span>
                </div>
            </div>
        </form>
    </div>

通常此代码适用于 .NET 站点:

$mech->submit_form(
    with_fields => {
        login => "somelogin",
        pass  => "somepass",
    },
    button => "submit_button_name",
);

但是你有奇怪的错误信息:你正在选择 "Login" 表格但是 $mech 正在搜索 "loginForm"...你能显示实际表格的 HTML 吗?

也没有必要做 $mech->cookie_jar(...) 因为 $mech 默认这样做。

更新 试试这个代码(Login 是你表单的 id 而不是 name):

$mech->submit_form(
    with_fields => {
        UserName => "somelogin",
        Password  => "somepass",
    },
);