Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: LWP::USERAGENT - POST through basic authentication

by Khen1950fx (Canon)
on Oct 10, 2011 at 16:55 UTC ( #930680=note: print w/ replies, xml ) Need Help??


in reply to LWP::USERAGENT - POST through basic authentication

This might help.

#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; my $ua = LWP::UserAgent->new; my $req = HTTP::Request->new; $req->method("POST"); $req->uri("http://www.example.com"); $req->authorization_basic('user', 'password'); print $ua->request($req)->as_string;


Comment on Re: LWP::USERAGENT - POST through basic authentication
Download Code
Re^2: LWP::USERAGENT - POST through basic authentication
by zantoro (Initiate) on Oct 11, 2011 at 13:51 UTC
    where do I put the $args?

      Where do I put the $args

      You don't. In some of the Net modules, you can use a %args for options, but since this is LWP, there's a slightly different way to do that. For example, in the example that I gave you, I tried to keep it simple, step-by-step. Lets look at another way to do it.

      $req = HTTP::Request->new(POST => $self->{'baseurl'}, $args);

      First, you're missing a shebang line( #!/usr/bin/perl ) and strictures. You also need to declare your variables with my. Another problem is your use of $self->{'baseurl'}---What's that? You didn't declare $self nor $args. Putting it altogether:
      #!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; #using http://www.example.com for our $url my $req = HTTP::Request->new(POST => 'http://www.example.com');
      Note that the url should be absolute; also, I dropped $self->{'baseurl'} and $args because they weren't necessary and didn't do anything. Now you know where to put $args:).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://930680]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2014-12-25 20:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (163 votes), past polls