in reply to Re^3: Crypt::SSLeay performing a HTTP POST
in thread Crypt::SSLeay performing a HTTP POST

Thanks! I think I am starting to understand. Below is my code. It hangs during the post and I am sure that it is incorrect, but do not know why. In poking around the documentation, it shows the URL:PORT which in my case is 443. I am believing that LWP is actually attempting a HTTP post to the URL on port 443 - but I need it to do a HTTPS post. I believe this because when I open a browser with the same URL:443, it hangs as well. I installed OpenSSL to its own directory, but see no mention that it is being accessed via LWP.

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

Replies are listed 'Best First'.
Re^5: Crypt::SSLeay performing a HTTP POST
by almut (Canon) on Jun 04, 2010 at 18:05 UTC

    I'd use Wireshark to see what's sent across the wire.

    Also, as I already mentioned yesterday, you need square brackets [ DATA=>our $USER, DATA=>our $PASS ]  (LWP needs them to disambiguate HTTP headers from HTML form key/value pairs).

Re^5: Crypt::SSLeay performing a HTTP POST
by Marshall (Canon) on Jun 06, 2010 at 07:54 UTC
    You do not need this port 443 stuff. That IS the standard port for HTTPS, Port Numbers - IANA — Internet Assigned Numbers Authority. I would take that out just to simplify things - don't repeat defaults...that's why there are defaults!

    See almuts post at Re: Crypt::SSLeay performing a HTTP POST again. "DATA=>our $USER, DATA=>our $PASS" is wrong. (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". If a syntax won't "fly" in a hash table definition, it won't "fly" in a POST. At the end of the day, your LWP thing is going to supply "field,value" pairs. This '=>' operator is called a "fat comma" and what is on the left has to be unique and what is on the right has to be valid just like you were defining a hash.

      (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>
        Actually, it's no problem to submit duplicate parameters (aka multi-valued field) — though unusual for login forms.

        In my limited LWP experience, I had never seen a multi-valued field like that. Perhaps I should have said, hey "this looks a bit strange. Are you sure that this is what is required and intended?". Yes, a normal sequence would be to authenticate before more data is exchanged.

        Thanks almut.