Forum Moderators: coopster & phranque

Message Too Old, No Replies

Sending a POST request within a perl script

         

reubensant

4:02 pm on Aug 1, 2005 (gmt 0)

10+ Year Member



Hello, I am developing a payment page and my payment provider has instructed me to use a particular URL to POST the credit card details to it. The url then just returns a response with a single line of text with the values:

name1=value1&name2=value2&name3=value3...

Also, this URL may take a number of seconds to reply. So, what I need is that when the client enters his credit card details (on a secure server) and clicks "Checkout", the "action" of the payment form should take him to "process.cgi". This script sends a POST request and awaits for the response from the payment provider. In the meantime, the client should recieve a "Please wait" message on his browser. When the response is recieved from the payment provider, the browser should automatically redirect to "done.cgi?=mode=success" or "done.cgi?mode=fail" according to the response from the server. Is that possible?

WWMike

4:56 pm on Aug 1, 2005 (gmt 0)

10+ Year Member



That sounds pretty much like what I'm trying to do. Review the suggestions at: [webmasterworld.com...]

rocknbil

7:54 pm on Aug 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Review the curl command. :-D

$result = `curl -d 'send=your&params=here' $secureGateway`;

-d means to manage the quoted text as data.
The string returned by the gateway will be in $result.
Also you may get a blank value in $result if you're not curling from a secure server, that is, your gateway won't respond with data of any value.

rocknbil

7:59 pm on Aug 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$result = qq¦curl -d 'send=&your&params' $secureGateway¦;

-d means to manage the quoted text as data.
The string returned by the gateway will be in $result.

Based on how you parse out the response, you just return the appropriate browser response. You should do this anyway to manage error checking. And I don't know of a way to do the "please wait" without multiple refreshes.

reubensant

3:38 pm on Aug 6, 2005 (gmt 0)

10+ Year Member



hello, $result seems to contain the original curl command instead of the response from the gateway :(

rocknbil

4:36 am on Aug 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Apologies, as you can see I had some . . issues editing the post and gave up. Execute the curl w. backticks.

$result = `curl -d 'your params' secureURL`;

reubensant

10:58 am on Aug 12, 2005 (gmt 0)

10+ Year Member



ok..no prob.. thanks or that

s1developer

12:17 pm on Aug 12, 2005 (gmt 0)

10+ Year Member



You could also do this using LWP as an alternative option, which would do it all in Perl and thereby avoid running an external command. I think something like this should work:

#---------
use LWP::UserAgent;
my $ua = new LWP::UserAgent;

my $response
= $ua->post('https://www.example.com/submit.cgi',
{ param1 => 'value1',
param2 => 'value2',
});

my $content = $response->content;
#---------

Then $content should contain whatever the server gave back to you, and you can then print it to the browser or whatever you want.

Ref: [search.cpan.org...]

Best of luck.
-Jer