develooper Front page | perl.beginners | Postings from May 2008

Passing Creadentials and parameters through http headers

Thread Next
From:
Prabu Ayyappan
Date:
May 7, 2008 02:42
Subject:
Passing Creadentials and parameters through http headers
Hi all,

I want to Pass the credentials and the Post parameters in a request and need to get the response content.

I tried with the following approach. 

1) Credentials are getting passed correctly however am not getting the parameter passed. 

2) If am passing the credentials in the url it is working fine. I want to pass the credential in header

3) Getting 401 - AUTH_REQUIRED Message

Method I:

use LWP::UserAgent;
use HTTP::Request;
use HTTP::Request::Common;
use Data::Dumper;
my $ua = new LWP::UserAgent;
$username = 'username';
$password = 'password';
$uri = 'https://url/goeshere';
$in = {'test1' => 'test'};
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(POST => $uri,Content => $in);
$req->authorization_basic($username, $password);
$req->header("Content-Type" => "application/x-www-form-urlencoded");
my $output=$ua->request($req)->content;
print Dumper $output;

Method II:

use LWP::UserAgent;
use HTTP::Request;
use HTTP::Request::Common;
use Data::Dumper;
my $ua = new LWP::UserAgent;
$in = {'test1' => 'test'};
my $res = $ua->post('https://username:password@url/goeshere', $in);
print Dumper $res->content;

Method III:

use LWP::UserAgent;
use HTTP::Request;
use HTTP::Request::Common;
use Data::Dumper;
my $ua = new LWP::UserAgent;
$url = "https://url/goeshere";
$in = {'test1' => 'test'};
$ua->credentials($url, 'TESTREALM', 'username' => 'password');
my $res = $ua->post($url, $in);
print Dumper $res->content;


Please guide me, 

I want to Pass both credentials and parameters through headers.

Thanks,
Prabu



      Unlimited freedom, unlimited storage. Get it now, on http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.html/

Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About