Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using LWP::UserAgent to post and receive data

Status
Not open for further replies.

RandyL712

Technical User
Feb 27, 2002
2
US
My objective is simple:

1) On form on my secure ( 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!

Code:
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 '[URL unfurl="true"]https://secure.iongate.com/iongate.asp',[/URL]
\%params
);

if ($res->is_success) {
my $returned_content = $res->content;
... [process returned content here]
}
[etc.]
 
I wanted to add that this file (test.cgi) is on a secure server, and that the server has SSLeay installed.
 
Unless I misunderstand you, you wish to send data from a from on one server to a form handling script on another. You can do this with the action attribute of the form tag. Just put in the whole url. If this doesn't accomplish exactly what your aiming for let me know, I have figured out how to use the LWP module to act as a middleman between a from and a from handling script, so I can walk you through it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top