Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1004069
  • 博文数量: 150
  • 博客积分: 3017
  • 博客等级: 少校
  • 技术积分: 3829
  • 用 户 组: 普通用户
  • 注册时间: 2011-11-19 14:40
个人简介

Now in Baidu WISE team

文章分类

全部博文(150)

文章存档

2014年(8)

2013年(31)

2012年(111)

分类: Python/Ruby

2012-03-30 12:42:53

Question:
When I'm tring to download a page by LWP, I got such response:


You do not have permission to view this directory or page using the credentials that you supplied because your Web browser is sending a WWW-Authenticate header field that the Web server is not configured to accept.

By wireshark, I found there is such information in received packages.

WWW_Authenticate:Negotiate
WWW_Authenticate:NTLM

Solution:
Use the module LWP::Authen::Negotiate
~agrolms/LWP-Authen-Negotiate-0.08/lib/LWP/Authen/Negotiate.pm
or install by `sudo apt-get install liblwp-authen-negotiate-perl`

No code change is required, just install the module.
That's the sample on CPAN

  1. #! /usr/bin/perl -w

  2.    use strict;
  3.    require LWP::UserAgent;

  4.    # uncomment if you want see what is going wrong messages
  5.    #
  6.    #use LWP::Debug qw(+);

  7.    my $ua = LWP::UserAgent->new;
  8.    my $response = $ua->get('');
  9.    if ($response->is_success) {
  10.       print $response->content; # or whatever
  11.    }
  12.    else {
  13.        die $response->status_line;
  14.    }


阅读(1028) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~