
RandyL712
Novice
Feb 27, 2002, 9:45 AM
Post #1 of 9
(809 views)
|
|
Using LWP::UserAgent to post and receive data
|
Can't Post
|
|
My objective is simple: 1) On form on my secure (https://) server, I collect data such as name, address, credit card number, etc. 2) data must be sent using server-to-server form post, and LWP::UserAgent seems the best candidate. 3) The receiving page (which is my credit card gateway) then returns a page like this: NAME=Joe Blow ADDRESS=123 Street Blvd. CARDNUM=1234xxxxxxxxxxxx etc. Each attribute on it's own line, separated by <br>. I know all of the attribute's names, so I don't need a code that will automatically turn any attribute given into a new scalar, I want to manualling convert each attribute into a scalar, does that make sense? In my limited experience, this seems safer. Once I have the data returned, I can take it from there, using the data in the scalars to finish the transaction for the customer. I just need help creating a CGI PERL code to use LWP::UserAgent to send my form data, and then receive from the IONGATE credit card gateway. I've played with the lwpcook samples, but I don't know enough of this to make it work! Any code samples to accomplish the above would be greatly appreciated. After some badgering, the gateway (IONGATE) provided these instructions. I hope someone can help me with this!
All you need to do is build a hash of keys/values, create a user agent with the LWP library, and then post a hash reference to Iongate: #!/usr/bin/perl -w use strict; use HTTP::Request::Common qw(POST); use LWP::UserAgent; $|=1; my %params = (); $params{'LOGIN'} = 'testgate'; $params{'AMOUNT'} = '15.00'; $aprams{'CARDTYPE'} = 'VISA'; $params{'CARDNUM'} = '4111111111111111'; $params{'EXPIRES'} = '1203'; ... [etc.] my $userAgent = new LWP::UserAgent; my $res = $userAgent->request( POST 'https://secure.iongate.com/iongate.asp', \%params ); if ($res->is_success) { my $returned_content = $res->content; ... [process returned content here] } [etc.]
|