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

Hi all, I am using the Http::Request with SSL connection to send my xml data(content) to the paymen gateway server. I am sinding the following header information,
'MIME-Version' => $self->MIME_Version, 'Content-Type' +=> $self->content_type, #'Content-length' = +> $self->content_length, 'Content-length' => + '1', 'Content-transfer-encoding' + => $self->content_transfer_encoding, 'Request-number' => + $self->request_number, 'Document-type' + => $self->document_type,
In this Content-Length = 239 as per the variable. I am getting the error as 413 huge data in the request. When I m removing Content-Length the request at least goes to server but for me it is mandatory to send this field as per the requirement given by the payment gateway server. If anybody has any idea or sugession please let me know. Thanks, SHAM...

Replies are listed 'Best First'.
Re: Content-Length for HTTP Header.
by clinton (Priest) on Aug 24, 2007 at 18:09 UTC
    In this Content-Length = 239 as per the variable.
    Are you sure? content_length() may return 239 in scalar context, but you're calling it in list context.

    You've only provided a snippet of the code, so I don't know what $self is, but I would check $http->header('Content-length') after constructing the HTTP::Request object, to see what value it has stored in Content-length

    Clint

      Hi clinton, following is the code snippet that I am using to get the SSL connection.
      use strict; use Data::Dumper; use LWP::UserAgent; use HTTP::Request; use Net::SSLeay qw(get_https post_https sslcat make_headers make_form) +; my $method = 'POST'; my $host = 'orbital1.paymentech.net'; my $uri = '/authorize'; ## This is the fake request we are generating my $xmlRequest = '<Request>'. '<NewOrder>'. '<MessageType>A</MessageType>'. '<BIN>000002</BIN>'. '<TerminalID>001</TerminalID>'. '<AVSzip>33333</AVSzip>'. '</NewOrder>'. '</Request>'; my ($page, $response, %reply_headers); my $MIME_Version = '1.0'; my $content_type = 'application/PTI42'; my $content_length = length $xmlRequest; my $content_transfer_encoding = 'text'; my $request_number = '1'; my $document_type = 'Request'; my $headers = make_headers( 'MIME-Version' => $MIME_Version +, 'Content-Type' => $content_type +, 'Content-length' => $content_length +, 'Content-transfer-encoding' => $content_tra +nsfer_encoding, 'Request-number' => $request_number +, 'Document-type' => $document_ty +pe, ); ($page, $response, %reply_headers) = post_https( $host, 443, $uri, $headers, $xmlRequest, ); print STDERR "\n========= page ======== \n" . Dumper($page); print STDERR "\n========= response ======== \n" . Dumper($respons +e); print STDERR "\n========= reply_headers ======== \n" . Dumper(%re +ply_headers); __END__ OUTPUT FOR ABOVE REQUEST IS =====> : ========= page ======== $VAR1 = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>413 Request Entity Too Large</title> </head> <body> <h1>Request Entity Too Large</h1> The requested resource<br/>/authorize<br/> does not allow request data with POST requests, or the amount of data provided in the request exceeds the capacity limit. <p> Additionally, a 413 Request Entity Too Large error was encountered while trying to use an ErrorDocument to handle t +he request. </p> </body> </html> '; ========= response ======== $VAR1 = 'HTTP/1.1 413 Request Entity Too Large'; ========= reply_headers ======== $VAR1 = 'CONTENT-TYPE'; $VAR2 = 'text/html; charset=iso-8859-1'; $VAR3 = 'DATE'; $VAR4 = 'Mon, 27 Aug 2007 06:11:29 GMT'; $VAR5 = 'CONNECTION'; $VAR6 = 'close';
      I am not sure if there is problem in my coding or else from the server side requirment. When I remove the conent-length tag from header request request seems to hit the server and generates the definate error(as given). Please suggest where I am missing or else what I should go for to get the working SSL connection. Thanks , SHAM...
        I've never used Net::SSLeay, but the docs say that the Content-Length and Content-Type headers are added automatically by post_https(). So if I remove your Content-Length header, the above script gives me:

        <?xml version="1.0" encoding="UTF-8"?> <Response> <QuickResponse HcsTcsInd="T" Version="2"> <ProcStatus>20412</ProcStatus> <StatusMsg StatusMsgLth="52">Precondition Failed: Security Informa +tion is missing</StatusMsg> </QuickResponse> </Response>

        The Content-length: 239 that you were seeing is the length of THEIR response, not your request. I think that Content-Length isn't the problem here - the problem is that you're not providing authorization details perhaps?

        Clint