CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Using LWP::UserAgent to post and receive data

 



RandyL712
Novice

Feb 27, 2002, 9:45 AM

Post #1 of 9 (1034 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!


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 'https://secure.iongate.com/iongate.asp',
\%params
);

if ($res->is_success) {
my $returned_content = $res->content;
... [process returned content here]
}
[etc.]



Jasmine
Administrator

Feb 27, 2002, 11:49 AM

Post #2 of 9 (1030 views)
Re: [RandyL712] Using LWP::UserAgent to post and receive data [In reply to] Can't Post

What error are you getting, if any?


Pro_4
User

Feb 27, 2002, 12:37 PM

Post #3 of 9 (1027 views)
Re: [RandyL712] Using LWP::UserAgent to post and receive data [In reply to] Can't Post

I don't know if this was just a typo when you posted the code but you misspelled param wrong, which would feed some of the data in wrongUnsure

Quote
$params{'LOGIN'} = 'testgate';
$params{'AMOUNT'} = '15.00';
$aprams{'CARDTYPE'} = 'VISA';
$params{'CARDNUM'} = '4111111111111111';
$params{'EXPIRES'} = '1203';





Just what i saw when skimming over it


RandyL712
Novice

Feb 27, 2002, 1:30 PM

Post #4 of 9 (1023 views)
Re: [Pro_4] Using LWP::UserAgent to post and receive data [In reply to] Can't Post

I know about the typo, sorry I posted without it fixed :)

What I need is that code put into a working .cgi file - I frankly can't get it working! For testing, just printing a parameter to the screen would let me know it's working, and I can't even get that to work! I've tried this to test:


Code
#!/usr/bin/perl -w 

use strict;
use CGI;
use HTTP::Request::Common qw(POST);
use CGI::Carp qw/fatalsToBrowser/;
use LWP::UserAgent;
$|=1;

my %params = ();

$params{'LOGIN'} = 'testgate';
$params{'AMOUNT'} = '15.00';
$params{'CARDTYPE'} = 'VISA';
$params{'CARDNUM'} = '4111111111111111';
$params{'EXPIRES'} = '1203';

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;
print "It worked";
} else {
print "It didn't work";
}


But I get the famous error 500 "Internal Server Error"... I would REALLY appreciate any help!


(This post was edited by RandyL712 on Feb 27, 2002, 2:51 PM)


Paul
Enthusiast

Feb 27, 2002, 3:38 PM

Post #5 of 9 (1018 views)
Re: [RandyL712] Using LWP::UserAgent to post and receive data [In reply to] Can't Post

Im guessing the error is due you not printing a header before printing text :)


(This post was edited by RedRum on Feb 27, 2002, 3:41 PM)


RandyL712
Novice

Feb 27, 2002, 3:47 PM

Post #6 of 9 (1014 views)
Re: [RedRum] Using LWP::UserAgent to post and receive data [In reply to] Can't Post

Okay, that cured the error. But it's still failing the "is_success" :)


Jasmine
Administrator

Feb 27, 2002, 5:17 PM

Post #7 of 9 (1011 views)
Re: [RandyL712] Using LWP::UserAgent to post and receive data [In reply to] Can't Post

I ran the code, looked at $@, and received the following error:

Protocol scheme 'https' is not supported

I've heard of this before, and that people used [url=http://search.cpan.org/search?dist=Net_SSLeay.pm]Net::SSLeay for their secure posting. Haven't tried it myself, though.

Good luck!


RandyL712
Novice

Feb 28, 2002, 2:31 PM

Post #8 of 9 (999 views)
Re: [Jasmine] Using LWP::UserAgent to post and receive data [In reply to] Can't Post

This file (which I've called test.cgi) is on a secure server, and SSLeay is installed on my server as well...


Jasmine
Administrator

Feb 28, 2002, 3:41 PM

Post #9 of 9 (997 views)
Re: [RandyL712] Using LWP::UserAgent to post and receive data [In reply to] Can't Post

Good. The docs for http://search.cpan.org/search?dist=Net_SSLeay.pm]Net::SSLeay would probably be the place for you to start. It offers this example:

[perl] ($page, $response, %reply_headers)
= post_https('www.bacus.pt', 443, '/foo.cgi', '', # 3
make_form(OK => '1',
name => 'Sampo'
));
[/perl]

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives