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

Looking for an example on performing a post with LWP. The page I am working on has two fields (user/password) and then a submit button. The submit but does not have a name - it is a name-less element. Code Below. Note $USER and $PASS come from the required file listed in line 1.

Sorry for the messed up post - I cleaned it up. No errors are thrown - just hangs. The DATA tags for the username/passowrd are the same. I am not responsible for the existing HTML - just trying to access the site.

require 'c:\ken2\config.pl'; use strict; use warnings; use LWP::UserAgent; my $url = "https://LINKGOESHERE/"; my $port = 443; my $lwp = LWP::UserAgent->new( ); my $response = $lwp->post($url, DATA=>our $USER, DATA=>our $PASS, VALU +E=>"Submit"); if($response->is_success){ print $response->content; } else{ print $response->status_line, "\n"; }

Replies are listed 'Best First'.
Re: performing a POST on HTTPS using LWP module
by Herkum (Parson) on Jun 03, 2010 at 14:21 UTC

      Thanks - I looked at that site already. My main obstacle is that the submit button does not have a name associated with it, so I am unsure how to submait a pair (key/value). Also - the two name fields for the username and password have the same name. I am presuming that I can give the key value the same and respond in the order they appear on the page.

Re: performing a POST on HTTPS using LWP module
by marto (Cardinal) on Jun 03, 2010 at 14:11 UTC

    Welcome to the Monastery, please don't ignore the formatting advice when posting, place code between code tags:

    <code> #!/usr/bin/perl # your code goes here </code>

    See also How do I post a question effectively?.

    Does your code generate any errors? Did you read the README.SSL file?

Re: performing a POST on HTTPS using LWP module
by almut (Canon) on Jun 03, 2010 at 14:33 UTC

    Are you sure you need the same field name "DATA" for both user and password? (just wondering — it's possible, but multi-valued fields are unusual for logins)

    Also, I think you need [ ... ] around the form parameters (otherwise, the key/value pairs would end up as HTTP headers).

    Why did you comment out use strict?  To get rid of the Bareword "Submit" not allowed while "strict subs" in use?  Better fix it... :)

    my $response = $lwp->post($url, [ DATA=>$USER, DATA=>$PASS, VALUE=>"Su +bmit" ]);

    Update: as for your updated node: I'd say you still need the [ ... ]

      I changed the line to

      my $response = $lwp->post($url, {DATA=>our $USER, DATA=>our $PASS, VAL +UE=>"Submit"} );

      no help - just hangs - no error

        Don't use a hashref ({...}) if you have multiple identical keys  (for this purpose, the API also allows an arrayref).

        my $hashref = {DATA=>"foo", DATA=>"bar", VALUE=>"Submit"}; use Data::Dumper; print Dumper $hashref; __END__ $VAR1 = { 'VALUE' => 'Submit', 'DATA' => 'bar' # where's 'foo'? };

        (not saying this will necessarily fix the hang, but it's wrong anyway)

        See also LWP::Debug.