Perl WWW :: Mechanize-身份验证错误获取URL [英] Perl WWW::Mechanize -- Authentication Error GETing URL

查看:134
本文介绍了Perl WWW :: Mechanize-身份验证错误获取URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Perl的Mechanize库填写Web表单.

I'm trying to fill out a web form using the Mechanize library of Perl.

每当我在搜索框中输入URL时,都会提示以下消息,并且我可以成功手动登录.

Whenever I enter the URL into the search box it prompts the below message, and I can manually login sucessfully.

但是,当我运行以下脚本时,出现以下错误:

However, when I run the below script, I get the following error:

如何使用我的$mech对象正确填写第一个身份验证盒凭据?

How do I correctly fill in the first Authentication Box credentials using my $mech object?

my $mech = WWW::Mechanize->new( 'keepalive' => 1 );

my $url = "http://URL/I/NEED/TO/ACCESS";
my $username = "username";
my $password = "password";

$mech->credentials($username, $password);
$mech->get($url);          <----------------- ERROR (LINE 93)

这是在请求的站点上运行wget的结果

Here are the results of running wget on the requested site

--2013-08-30 11:16:17--  http://moss.micron.com/MFG/ProbeTest/Lists/Manufacturing%20Requests/AllItems.aspx
Resolving moss.micron.com... 137.201.88.118
Connecting to moss.micron.com|137.201.88.118|:80... connected.
HTTP request sent, awaiting response... 
  HTTP/1.1 401 Unauthorized
  Server: Microsoft-IIS/7.0
  WWW-Authenticate: Negotiate
  WWW-Authenticate: NTLM
  X-Powered-By: ASP.NET
  MicrosoftSharePointTeamServices: 12.0.0.6341
  Date: Fri, 30 Aug 2013 17:16:17 GMT
  Connection: keep-alive
  Content-Length: 0
Authorization failed.

推荐答案

使用旧版本的Mechanize,您可以将 WWW :: Mechanize 软件包并提供您自己的凭据例程:

With older versions of Mechanize you could subclass the WWW::Mechanize package and provide your own credentials routine:

package MyMech;

use vars qw(@ISA);
@ISA = qw(WWW::Mechanize);

sub get_basic_credentials {
  my ($self, $realm, $uri) = @_;
  return( "user", "password" );
}

然后在程序中使用此程序包而不是WWW :: Mechanize:

Then in your program use this package instead of WWW::Mechanize:

package main;

my $mech = MyMech->new();
$mech->get( $url );

更新

您已经更新了问题,以指示需要NTLM身份验证.查看 LWP :: Authen :: Ntlm 在CPAN上.

You've updated your question to indicate the requirement of NTLM authentication. Check out LWP::Authen::Ntlm on CPAN.

这篇关于Perl WWW :: Mechanize-身份验证错误获取URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆