tcf22 has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to send XML to a payment server, in order to keep processing in a central location. Anyway, I'm generating the XML with XML::Simple and sending with LWP::UserAgent. The XML looks fine(it is below), but I'm getting the following response 500 - Too many header lines (limit is 128), but I'm not sending any additional headers.
<?xml version="1.0"?> <PaymentRequest> <PAY_CC_NUMBER>xxxxxxxxxxxx1234</PAY_CC_NUMBER> <PAY_OID>Test_ID</PAY_OID> <PAY_EMAIL></PAY_EMAIL> <PAY_CC_EXPIRE>1203</PAY_CC_EXPIRE> <PAY_PROCESSOR>Processor</PAY_PROCESSOR> <PAY_ZIP>12345</PAY_ZIP> <PAY_CC_TYPE>Visa</PAY_CC_TYPE> <PAY_MERCHANT>test2</PAY_MERCHANT> <PAY_FULL_NAME>Test Customer</PAY_FULL_NAME> <PAY_AMOUNT>1.00</PAY_AMOUNT> <PAY_CITY>City</PAY_CITY> <PAY_ADDR>123 Test st #293 </PAY_ADDR> <PAY_FUNCTION>Authorize</PAY_FUNCTION> <PAY_STATE>PA</PAY_STATE> <PAY_CVV2>111</PAY_CVV2> <PAY_COUNTRY>US</PAY_COUNTRY> <PAY_SCRIPT>test.cgi</PAY_SCRIPT> </PaymentRequest>

Here is the Perl code:
use strict; use warnings; use XML::Simple; use LWP::UserAgent; my $data = ##XML Data from external source. my $xml; eval { $xml = XMLout($data, rootname => 'PaymentRequest', xmldecl => '<?xml version="1.0"?>', noattr => 1); }; if ($@) { ##Error Handling } my $ua = new LWP::UserAgent; my $req = new HTTP::Request('POST', "http://$server/pay.cgi"); $req->content_type('text/xml'); $res = $ua->simple_request($req); if (! $res->is_success) { ##Error Handling }

Replies are listed 'Best First'.
Re: Problems sending XML to webserver
by ajdelore (Pilgrim) on Aug 21, 2003 at 15:33 UTC

    A few ideas/questions:

    1. Try print $req->as_string to see what your request looks like.

    2. When do you attach the XML to the request? I don't see it anywhere in this code. Maybe something like:

      $req = new HTTP::Request ('POST', 'http://server/pay.cgi', 'text/xml', + $xml)

    3. You are sending this via a POST. That suggests to me that you need to stringify the XML and assign it to a CGI variable name.

    Its not the total answer, but I hope it helps.

    </ajdelore>

      I must have forgot to paste the line
      $req->content($xml);
      but it is in my code.
Re: Problems sending XML to webserver
by antirice (Priest) on Aug 21, 2003 at 15:34 UTC

    ...are you sure this is the code you have? $xml isn't submitted to the server at all. Of course, the script also complains about the declaration of $res. As a side note, please tell me that http is a typo and should actually be https. Otherwise you are sending complete credit card information across the internet in plain text.

    Please change the code so we can help. :)

    antirice    
    The first rule of Perl club is - use Perl
    The
    ith rule of Perl club is - follow rule i - 1 for i > 1

Re: Problems sending XML to webserver
by tcf22 (Priest) on Aug 21, 2003 at 16:44 UTC
    I was checking the logs on the payment server ($server), and the requests are going through fine and returning a 200 response. I wrote the XML being returned to a log and it looks fine.
    Content-Type: text/xml <?xml version="1.0"?> <PaymentResponse> <PAY_AVS_RESPONSE>Y</PAY_AVS_RESPONSE> <PAY_CVV2_RESPONSE>M</PAY_CVV2_RESPONSE> <PAY_AUTH_RESPONSE>APPROVED</PAY_AUTH_RESPONSE> <PAY_STATUS>1</PAY_STATUS> <PAY_APPROVAL>123456</PAY_APPROVAL> <PAY_RESPONSE>APPROVED</PAY_RESPONSE> </PaymentResponse>
    So it now appears that the payment server recieves the request fine, and response fine, but for some reason, when the requesting server recieves the response, something goes wrong, and I have no idea why. Hopefully this extra info will give someone else an idea.

      Just wondering, but what server software are you using?

      antirice    
      The first rule of Perl club is - use Perl
      The
      ith rule of Perl club is - follow rule i - 1 for i > 1

        I've narrowed the error message to the following function in Net::HTTP::Methods.
        This is the code. I've added the $headers variable to keep track of the lines. I'm probably missing something, but this one has me boggled. Why is it dieing. $line_count should only be 4 when it dies.
        sub _read_header_lines { my $self = shift; my $junk_out = shift; my @headers; my $line_count = 0; my $max_header_lines = ${*$self}{'http_max_header_lines'}; my $headers = ''; while (my $line = my_readline($self)) { $headers .= "$line_count: $line\n"; if ($line =~ /^(\S+)\s*:\s*(.*)/s) { push(@headers, $1, $2); } elsif (@headers && $line =~ s/^\s+//) { $headers[-1] .= " " . $line; } elsif ($junk_out) { push(@$junk_out, $line); } else { die "Bad header: '$line'\n"; } if ($max_header_lines) { $line_count++; if ($line_count >= $max_header_lines) { die "Too many header lines($line_count) (limit is $max_header_ +lines) They are:\n$headers"; } } } return @headers; }
        Error:
        Too many header lines(128) (limit is 128) They are: 0: Server: Microsoft-IIS/5.0 1: Date: Thu, 21 Aug 2003 20:55:08 GMT 2: Connection: close 3: Use of uninitialized value in concatenation (.) or string
        IIS...I know, I know, but its not my choice.