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

Hi

I have a task to read the view source of a Share Point site and pick the email address from the view source.

I have tried as I do usually using get, UserAgent, robot etc.. But I couldn't anything other than 401 unauthorized Error.

I have tried passing the cridentials through header method of HTTPRequest, credentials method of UserAgent still my problem didn't get solved.

Here are the code snippets which I have tried in different ways. It would be great, if you someone help me on this. Thanks in Advance.

#!/usr/bin/perl -w use strict; use URI::Escape; use LWP::Simple; use LWP 5.64; use LWP::UserAgent; use LWP::RobotUA; require HTTP::Request; my $url_template = "<sharepoint website>"; # SOrry I cann't provi +de site name becoz itz our compnay interenal site. which I cann't dis +close my $ua = LWP::UserAgent->new; $ua->credentials('<sharepoint website>:80', '', '<userid>', '<pass +word>'); my $request = HTTP::Request->new(GET => "$url_template"); my $response = $ua->request($request) or print "Failed to send req +uest: $!"; # error check $content = $response->content(); # document OK #$response->is_success() || warn $response->message(); if ($response->is_success) { print $response->content; } else { print "Error: " . $response->status_line . "\n"; } or my $request = HTTP::Request->new(GET => "$url_template"); $request->content_type('text/html'); $request->authorization_basic('<userid>', '<password>'); #$request->header( $field => $value ) #my $response = $ua->get($url_template); my $response = $ua->request($request); if ($response->is_success) { $content = $response->decoded_content; # or whatever print $content; } else { die $response->status_line; } or # create robot my $robot = LWP::RobotUA->new('Mozilla/5.0 (Windows XP; U) Opera 6 +.0 [en]', '<emailid>'); # temporarily set delay to 0 minutes instaed of 10 $robot ->delay(0); my $request = HTTP::Request->new('GET', $url_template); # carry out network access my $response = $robot->request($request);
  • Comment on Unable to Access Share Point Site using Perl- 401 Unauthorized Error
  • Download Code

Replies are listed 'Best First'.
Re: Unable to Access Share Point Site using Perl- 401 Unauthorized Error
by Anonymous Monk on Jul 29, 2011 at 17:26 UTC

    What does the robots.txt say? Is your script avoiding the request because of that?

    Are your credentials correct? What if you try to get there manually?

    Is the server turning you down? What if you use a non corp-standard browser to make the request manually?

      Hi Thanks for your reply.

      When I do it manually, there are the steps, I followed.

      I hit the URL in browser, as soon as it loaded, it asks me enter my credentials, after entered it is opened. I just took the view source of the page and get the email address from that. (This is manual process)

      my Credentials are perfectly correct.

      robots.txt, I didn't check, I don't think there is some problem with that since it is our internal sharepoint website.

      Server is up and running all the time.

      I don't understand, what do you mean by "non Corp-standard browser to make the request manually""... you mean to say use Opera or Chrome????.

      What I think is, the way we pass the credentials is wrong or it is not accepting it properly.

      or there should be some other specific way to access the sharepoint website with the credentials.

      Please help me out.

      Thanks

      -Sunil