0

My work requires an authorization for internet use. I log in, and after that it recognizes me and lets me access whatever I need.

I have been using POSTMAN to test send to and receive from a company RESTful service. It automatically uses my same internet use auth at the other end to give my user account POST and GET permissions.

Now, I am trying to automate with a perl script and it won't authorize. The owner of the RESTful service says if I make a windows/.net application it will authorize automatically, but that isn't an option.

Any suggestions? I would think I could just do special headers or something and duplicate whatever windows is doing....

I have been asked to provide what I have done so far

#!/usr/local/bin/perl

use strict;
use LWP::UserAgent;

my $ua=LWP::UserAgent->new;
my $server_endpoint = "The post destination";
my $req= HTTP::Request->new(POST => $server_endpoint);
$req->header('content-type' => 'application/json');

my $post_data="[ SOME JSON HERE ]";
$req->content($post_data);

my $resp = $ua->request($req);
if($resp->is_success){
    my $message = $resp->decoded_content;
    print "received reply : $message\n";
}
else{
    print "post error code : ",$resp->code,"\n";
    print "post error message : ",$resp->message,"\n";
}
mrfish
  • 64
  • 7

2 Answers2

3

In the past when I had to authenticate against an IIS server I had to use LWP::Authen::Ntlm to get it to authenticate.

For more information about LWP::Authen::Ntlm, see https://metacpan.org/pod/LWP::Authen::Ntlm

The main "pitfalls" I had is that keepalive is required, and that newer versions of IIS now use Digest, and not NTLM

In those cases, I simply switched to the built-in LWP::Authen::Digest (it comes inside LWP)

titanofold
  • 2,852
  • 1
  • 15
  • 21
Noam Rathaus
  • 5,405
  • 2
  • 28
  • 37
  • Thanks nrathaus, this looks like it will probably work for me. Now for the dumb question - how do I translate a posting address for the service (https://someplace.net/DataService/save/GROUP") into the first $ua credentials box? – mrfish Feb 06 '14 at 21:06
  • This isn't look like credentials it looks like a URL – Noam Rathaus Feb 07 '14 at 13:15
0

Have a look at a similar question (scroll up to the top see the question) and see if the included bit of Perl code doesn't help...

LWP::UserAgent HTTP Basic Authentication

The short version is that it doesn't appear that your Perl code above includes any login information and this POSTMAN plugin may be sending over cached login info that your Perl code is not yet aware of.

Community
  • 1
  • 1
Rick Sarvas
  • 769
  • 10
  • 20