Tuesday, January 12, 2010

PERL TCP Socket Codes with LWP (HTTPS/SSL, POST method)

Planned to delay this but what the hack, just let the series continues.

For such connection, LWP is needed:


use LWP::UserAgent; #call up the LWP module
my $ua = LWP::UserAgent->new;

$req = new HTTP::Request POST => "https://www.yourSSLURL.com/script?var=variable";
$req->header('Accept' => 'text/html');

$req->content_type('application/x-www-form-urlencoded');
$req->content("a=a&b=c&c=c");


$res = $ua->request($req);

#to transfer $res->as_string to @HTML array
open (TEMP, ">temp.txt");
print TEMP $res->as_string;
close (TEMP);
open (TEMP, "temp.txt");
@HTML = ;
close(TEMP);
`rm -f temp.txt`; #Use Unix command to remove the temporary file, you can also use randomized filename to avoid duplicates



There you go. Still cannot think of a way to bypass LWP. Maybe someday...




UPDATE - You may see this error if your web server cannot handle LWP SSL:

501 Protocol scheme 'https' is not supported (Crypt::SSLeay not installed) Content-Type: text/plain Client-Date: Sun, 21 Feb 2010 02:31:47 GMT

Client-Warning: Internal response LWP will support https URLs if the Crypt::SSLeay module is installed. More information at .


OR


use Crypt::SSLeay; #LWP will support https URLs if the Crypt::SSLeay module is installed.
More information at .



That means you need to install Crypt::SSLeay PERL module beside LWP.

Here's the instruction at your PERL ppm:

ppm> install http://theoryx5.uwinnipeg.ca/ppms/Crypt-SSLeay.ppd

to install Crypt::SSLeay in your web server.

No comments:

Post a Comment