(1) Each field that you supply information for will have a unique name, two fields can't both be called "DATA". (2) I doubt that this is the place for a Perl scoping declaration like "our,my,local".

Actually, it's no problem to submit duplicate parameters (aka multi-valued field) — though unusual for login forms.  And our is ok there, too:

Test webserver

#!/usr/bin/perl { package TestWebServer; use HTTP::Server::Simple::CGI; use base qw(HTTP::Server::Simple::CGI); my %dispatch = ( '/login' => \&resp_login, # ... ); sub handle_request { my $self = shift; my $cgi = shift; my $path = $cgi->path_info(); my $handler = $dispatch{$path}; if (ref($handler) eq "CODE") { print "HTTP/1.1 200 OK\r\n"; $handler->($cgi); } else { print "HTTP/1.1 404 Not found\r\n"; print $cgi->header, $cgi->start_html('Not found'), $cgi->h1('Not found'), $cgi->end_html; } } sub resp_login { my $cgi = shift; # CGI.pm object return if !ref $cgi; my %params = $cgi->Vars(); my ($user, $pass) = split /\0/, $params{DATA}; print $cgi->header, $cgi->start_html("Info"), $cgi->p("You sent: user='$user', pass='$pass'"), $cgi->end_html; } } my $pid = TestWebServer->new(8080)->background(); print "Use 'kill $pid' to stop server.\n";

LWP script:

#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; { our $USER = "foo"; our $PASS = "bar"; } my $ua = LWP::UserAgent->new(); my $resp = $ua->post( "http://localhost:8080/login", [ DATA => our $USER, DATA => our $PASS, ] ); if ($resp->is_success) { print $resp->decoded_content; } else { print $resp->status_line; }

Demo session:

$ ./HTTPserver.pl Use 'kill 25807' to stop server. HTTP::Server::Simple: You can connect to your server at http://localho +st:8080/ $ ./lwp-test.pl <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"> <head> <title>Info</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +" /> </head> <body> <p>You sent: user='foo', pass='bar'</p> </body> </html>

In reply to Re^6: Crypt::SSLeay performing a HTTP POST by almut
in thread Crypt::SSLeay performing a HTTP POST by kbarker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.