Problems with STDIN and POST data

S

SergioQ

Hello all,

Am having some very serious problems reading the POST data that is
being sent to my Perl script. The full code (minus my email address
is below). And essentially what I am getting back via email reports
is that that there is data being sent via POST, and tht it has a
length of 1431. Yet all my attempts to read it are failing
miserably. If anyone can help me out, I would soooo appreciate it.

Thank you so much.

Here is the FULL CODE:

#!/usr/bin/perl

use strict;
use MainMod;
use HTTP::Request;
use LWP::UserAgent;
use CGI qw:)standard);

my $out_msg = "";
my %variable;
my $serg_bffr;

read STDIN, $serg_bffr, $ENV{'CONTENT_LENGTH'};

my $sendmail = "/usr/sbin/sendmail -t";
open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";

print SENDMAIL ---my email address goes here---
print SENDMAIL ---my email address goes here---
print SENDMAIL "Subject: IPN Stuff\n";
print SENDMAIL "\n";
print SENDMAIL "$ENV{REQUEST_METHOD}\n";
print SENDMAIL "$ENV{'CONTENT_LENGTH'}\n";
print SENDMAIL length($serg_bffr) . "\n";
print SENDMAIL "$serg_bffr\n";

close(SENDMAIL);

PrintItOut("done");
exit (0);
 
X

xhoster

SergioQ said:
Hello all,

Am having some very serious problems reading the POST data that is
being sent to my Perl script. The full code (minus my email address
is below). And essentially what I am getting back via email reports
is that that there is data being sent via POST, and tht it has a
length of 1431. Yet all my attempts to read it are failing
miserably.

"Failing miserably" is about as bad as "doesn't work". What actually
happens?

Does your hard drive reformat itself and then your cpu set itself on fire?
Here is the FULL CODE:

#!/usr/bin/perl

use strict;
use MainMod;
use HTTP::Request;
use LWP::UserAgent;
use CGI qw:)standard);

Since you are using it, why not use CGI to read from STDIN for you?

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
S

SergioQ

"Failing miserably" is about as bad as "doesn't work".  What actually
happens?
I see that there is PPOST data, and it has length, but what I read
back is nothing.


Since you are using it, why not use CGI to read from STDIN for you?


This is a Perl script for Paypal's IPN. Below is their sample
script. And you'll see there's a section "# post back to PayPal
system to validate" and since I don't know what's coming in, and in
what format, how can I tack it on and send it back?


THIS IS FROM PAYPAL
#!/usr/bin/perl

# read post from PayPal system and add 'cmd'
read (STDIN, $query, $ENV{'CONTENT_LENGTH'});
$query .= '&cmd=_notify-validate';

# post back to PayPal system to validate
use LWP::UserAgent;
$ua = new LWP::UserAgent;
$req = new HTTP::Request 'POST','http://www.paypal.com/cgi-bin/
webscr';
# note: if you have SSL encryption Enabled, use <https://
www.paypal.com/cgi-bin/webscr> above
$req->content_type('application/x-www-form-urlencoded');
$req->content($query);
$res = $ua->request($req);

# split posted variables into pairs
@pairs = split(/&/, $query);
$count = 0;
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$variable{$name} = $value;
$count++;
}

# assign posted variables to local variables
# note: additional IPN variables also available -- see IPN
documentation
$item_name = $variable{'item_name'};
$receiver_email = $variable{'receiver_email'};
$item_number = $variable{'item_number'};
$invoice = $variable{'invoice'};
$a = $variable{'custom'};
$payment_status = $variable{'payment_status'};
$payment_gross = $variable{'payment_gross'};
$txn_id = $variable{'txn_id'};
$payer_email = $variable{'payer_email'};
$amount = $variable{'amount'};
$on0 = $variable{'option_name1'};
$os0 = $variable{'option_selection1'};
$status = $res->content;
$note = $variable{'memo'};


if ($res->is_error) {
# HTTP error
}
elsif ($res->content eq 'VERIFIED') {
# check the payment_status=Completed
# check that txn_id has not been previously processed
# check that receiver_email is an email address in your PayPal account
# process payment
# print to screen the following if the IPN POST was VERIFIED


print "content-type: text/plain\n\nOK\n";
print "<html><head><title>IPN Screendump</title></head>\n";
print "<body>your email address is <b>$payer_email</b>\n";
print "<br>you paid <b>$payment_gross</b>\n";
print "<br>you paid for <b>$item_number</b>\n";
print "<br>the color of your order was <b>$os0</b>\n";
print "<br>the value of custom was <b>$a</b>\n";
print "<br>the status was<b>$status</b>\n";
print "<br>the note said <b>$note</b>\n";
print "<br>the transaction id was <b>$txn_id</b>\n";
print "<br>the payment status was<b>$payment_status</b>\n";
print "</body></html>\n";


}
elsif ($res->content eq 'INVALID') {
# log for manual investigation
# print to screen the following if the IPN POST was INVALID

print "content-type: text/plain\n\nOK\n";

print "<html><head><title>IPN Screendump</title></head>\n";
print "<br>the status was<b>$status</b>\n";
print "</body></html>\n";


}
else {
# error
}
 
X

xhoster

SergioQ said:
I see that there is PPOST data, and it has length, but what I read
back is nothing.

Then check the return value of the "read" function and if it is undef
(as opposed to 0) see what is in $!.

Are you sure that whatever is generating these POST requests, or whatever
is proxying them to you, isn't lying about CONTENT_LENGTH?

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
T

Todd Wade

Since you are using it, why not use CGI to read from STDIN for you?

IIRC It does automatically when use()d in this manner. Thats why
$serg_bffr is empty.

Todd W.
 
G

Gunnar Hjalmarsson

Todd said:
IIRC It does automatically when use()d in this manner. Thats why
$serg_bffr is empty.

I think your memory gives way. ;-) IIRC, STDIN is emtied only when you
create a CGI object or call one of the CGI.pm functions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top