Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: What can be the reasons for bad request ??

by Sham (Novice)
on Sep 08, 2007 at 12:39 UTC ( [id://637823]=note: print w/replies, xml ) Need Help??


in reply to Re: What can be the reasons for bad request ??
in thread What can be the reasons for bad request ??

Here is the test code I m using .
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 $host = 'orbital2.paymentech.net'; my $uri = '/authorize'; ## This is the initial test xml-request for authorization my $xmlRequest = '<Request>'. '<NewOrder>'. '<IndustryType>EC/IndustryType>'. '<MessageType>A</MessageType>'. '<BIN>000002</BIN>'. + '<TerminalID>001</TerminalID>'. '<AccountNum>4111111111111111</AccountNum>'. '<Exp>102009</Exp>'. '<CurrencyCode>840</CurrencyCode>'. '<CurrencyExponent>2</CurrencyExponent>'. '<CardSecVal>213</CardSecVal>'. '<AVSzip>33408</AVSzip>'. '<AVSaddress1>test address</AVSaddress1>'. '<AVScity>miami</AVScity>'. '<AVSstate>Florida</AVSstate>'. '<AVSphoneNum>5618926384</AVSphoneNum>'. '<AVSname>Raj Malahotra</AVSname>'. '<AVScountryCode>US</AVScountryCode>'. '<AVSDestzip>33408</AVSDestzip>'. '<AVSDestaddress1>Dest addresss</AVSDestaddres +s1>'. '<AVSDestcity>testcity</AVSDestcity>'. '<AVSDeststate>Florida</AVSDeststate>'. '<AVSDestname>Raj Malahotra</AVSDestname>'. '<AVSDestcountryCode>US</AVSDestcountryCode>'. '<CustomerProfileFromOrderInd>A</CustomerProfi +leFromOrderInd>'. '<OrderID>091933208935</OrderID>'. '<Amount>15.00</Amount>'. '<BMLShippingCost>15.00</BMLShippingCost>'. + '<BMLTNCVersion>5</BMLTNCVersion>'. + '</NewOrder>'. '</Request>'; my ($page, $response, %reply_headers); ## As per the specifications given in the pdf of Paymentech my $MIME_Version = '1.0'; my $content_type = 'application/PTI41'; my $content_length = length $xmlRequest; my $content_transfer_encoding = 'text'; my $request_number = '1'; my $document_type = 'Request'; #my $CRLF = "\x0d\x0a"; #my $CRLF = "\r\n"; my $CRLF = $Net::SSLeay::CRLF; 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, ); #$headers = "POST /AUTHORIZE HTTP/1.0" . $CRLF . $headers; $headers = "POST /AUTHORIZE HTTP/1.0\r\n" . 'Host: ' . $host . ': 443' . "\r\n" . "Accept: */*\r\n" . $headers; $Net::SSLeay::trace = 3; # 0=no debugging, 1=ciphers, 2=trace, 3=dump + data ($page, $response, %reply_headers) = post_https( $host, 443, $uri, $headers, $xmlRequest ); print STDERR "\n========= headers ======== \n" . Dumper($headers) +; print STDERR "\n========= request ======== \n" . Dumper($xmlReque +st); 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);
Please suggest if it needs any change. Thanks, SHAM...

Replies are listed 'Best First'.
Re^3: What can be the reasons for bad request ??
by dorko (Prior) on Sep 08, 2007 at 14:02 UTC
    I notice you're explicitly using Net::SSLeay and you've commented out LWP. When I work with SSL, I continue using LWP and when LWP sees an HTTPS URL, it just auto-magically uses Crypt::SSLeay to open the SSL connection. I never have to use Net::SSLeay anywhere in my code. Is there a specific reason you're using Net::SSLeay directly?

    From the SSL readme with LWP:

    SSL SUPPORT
    -----------
    
    The libwww-perl package has support for using SSL/TLSv1 with its HTTP
    client and server classes. This support makes it possible to access
    https schemed URLs with LWP. Because of the problematic status of
    encryption software in general and certain encryption algorithms in
    particular, in several countries, libwww-perl package doesn't include
    SSL functionality out-of-the-box.
    
    Encryption support is obtained through the use of Crypt::SSLeay or
    IO::Socket::SSL, which can both be found from CPAN. While libwww-perl
    has "plug-and-play" support for both of these modules (as of v5.45),
    the recommended module to use is Crypt::SSLeay. In addition to
    bringing SSL support to the LWP package, IO::Socket::SSL can be used
    as an object oriented interface to SSL encrypted network sockets.
    
    There is yet another SSL interface for perl called Net::SSLeay. It has
    a more complete SSL interface and can be used for web client
    programming among other things but doesn't directly support LWP.
    
    The underlying SSL support in all of these modules is based on OpenSSL
    <http://www.openssl.org/> (formerly SSLeay). For WWW-server side SSL
    support (e.g. CGI/FCGI scripts) in Apache see <http://www.modssl.org/>.
    

    Cheers,

    Brent

    -- Yeah, I'm a Delt.
      Further to this, when you do need to use Net::SSLeay (such as when writing an SSL capable network server) there are already modules which quite capably abstract the SSL part of the communications (eg: IO::Socket::SSL, HTTP::Daemon::SSL, etc).

      Pretty much the only time you need to use Net::SSLeay directly is when you're doing something strange like:

      • being specific about SSL versions and capabilities (partially covered in IO::Socket::SSL),
      • verifying peer certificates and other certificates in their chain-of-trust (partially covered in IO::Socket::SSL),
      • implementing non-standard extensions to SSL.

      I find Net::SSLeay most useful for its documentation of the SSL related options (most of which can be used by IO::Socket::SSL and LWP through Crypt::SSLeay).

      -David

      This is what I was iplementing previously by using the LWP::UserAgent. 1. Firstly I was getting the error as : LWP::UserAgent::_need_proxy: Not proxied I could not get which value should I put variable ENV{HTTP_PROXY}, I did try for my network's proxy address with port 8080 as well as with 443(I was not sure for this) but I could not fix the problem. 2 Secondly I could not create the required headers with this method. As I need to pass 'POST /AUTHORIZE HTTP/1.1'(not in key value form but simple text) this text with the header when Unless I send complete header info their server will not respond. So I tried to have specific implemetation for SSL that is the reason I used NET::SSLeay. Here is the code I was using.
      use strict; use Data::Dumper; use LWP::UserAgent; use HTTP::Request; use HTTP::Headers; use LWP::Debug qw(+); my $method = 'POST'; my $host = 'orbital1.paymentech.net'; my $uri = '/authorize'; $uri = 'https://orbital1.paymentech.net/authorize'; ## This is the fake request we are generating my $xmlRequest = '<?xml version="1.0" encoding="UTF-8"?>'. '<Request>'. '<NewOrder>'. '<IndustryType>EC</IndustryType>'. '<MessageType>A</MessageType>'. '<BIN>000002</BIN>'. '<TerminalID>001</TerminalID>'. '<AccountNum>4111111111111111</AccountNum>'. '<Exp>102009</Exp>'. '<CurrencyCode>840</CurrencyCode>'. '<CurrencyExponent>2</CurrencyExponent>'. '<CardSecVal>213</CardSecVal>'. '<AVSzip>33408</AVSzip>'. '<AVSaddress1>test address</AVSaddress1>'. '<AVScity>miami</AVScity>'. '<AVSstate>Florida</AVSstate>'. '<AVSphoneNum>5618926384</AVSphoneNum>'. '<AVSname>Raj Malahotra</AVSname>'. '<AVScountryCode>US</AVScountryCode>'. '<AVSDestzip>33408</AVSDestzip>'. '<AVSDestaddress1>Dest addresss</AVSDestaddres +s1>'. '<AVSDestcity>testcity</AVSDestcity>'. '<AVSDeststate>Florida</AVSDeststate>'. '<AVSDestname>Raj Malahotra</AVSDestname>'. '<AVSDestcountryCode>US</AVSDestcountryCode>'. '<CustomerProfileFromOrderInd>A</CustomerProfi +leFromOrderInd>'. '<OrderID>091933208935</OrderID>'. '<Amount>15.00</Amount>'. '<BMLShippingCost>15.00</BMLShippingCost>'. + '<BMLTNCVersion>5</BMLTNCVersion>'. + '</NewOrder>'. '</Request>'; my $MIME_Version = '1.1'; my $content_type = 'application/PTI42'; my $content_length = length($xmlRequest); my $content_transfer_encoding = 'text'; my $request_number = '1'; my $document_type = 'Request'; my $header = HTTP::Headers->new; $header->header ( 'MIME-Version' => $MIME_Version, 'Content-Type' => $content_type, 'Content-length' => $content_length, + 'Content-transfer-encoding' => $content_transfer_encodi +ng, 'Request-number' => $request_number, 'Document-type' => $document_type, + ); my $fix_headres = 'POST /AUTHORIZE HTTP/1.1' . "\r\n" . $header; my $HTTP_req = HTTP::Request->new($method,$uri,$header,$xmlRequest) ; my $UserAgent = LWP::UserAgent->new(); #$UserAgent->env_proxy; my $host_response = $UserAgent->request($HTTP_req); #print STDERR "\n========= headers ======== \n" . Dumper($header) +; #print STDERR "\n========= request ======== \n" . Dumper($HTTP_re +q); #print STDERR "\n========= response ======== \n" . Dumper($host_r +esponse); __END__
      When I use the variable $fix_headres(which is created externally with the required headers) in the HTTP::Request->new($method,$uri,$fix_headres,$xmlRequest) it gives error of bad headers. Please suggest on this issue where should I concentrate. Thanks... SHAM.
Re^3: What can be the reasons for bad request ??
by derby (Abbot) on Sep 08, 2007 at 14:35 UTC

    Well ... your XML is invalid:

    my $xmlRequest = '<Request>'. '<NewOrder>'. '<IndustryType>EC/IndustryType>'. ...
    should be
    my $xmlRequest = '<Request>'. '<NewOrder>'. '<IndustryType>EC</IndustryType>'.
    see the missing angle bracket after EC? But maybe that's just a posting error.

    -derby
      I would have jumped !!!! if it would have been the problem . Unfortunately it was not the problem, but thanks for notifying that. Thanks, SHAM....
        Hi I'm having the exact same problems as you. I've narrowed it down to the custom headers that are being built. This isnt part of the problem, but I see you are hitting the production url- not sure if you are aware, just wanted to point that out. https://orbitalvar1.paymentech.net is the testing url
        Check your header definition. Use Mime-version, rather than Mime_version (hyphen; not underscore).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://637823]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-04-24 20:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found