in reply to Difference between curl and Net;;SSLeay for getting the SSL connection

There's no need to use Net::SSLeay to do what you describe in perl, instead use the module LWP::UserAgent.

When LWP::UserAgent gets a url that starts with 'https://' it automatically loads and uses Crypt::SSLeay to handle SSL.

LWP::UserAgent provides a very simple API which allows you to talk to HTTP servers, which is basically all you need to do here.

Next time, please format your post using the allowed HTML tags... it'll make it much easier for others to read.

-David

  • Comment on Re: Difference between curl and Net;;SSLeay for getting the SSL connection

Replies are listed 'Best First'.
Re^2: Difference between curl and Net;;SSLeay for getting the SSL connection
by Sham (Novice) on Sep 15, 2007 at 06:01 UTC
    Hi David, What you are saying is very correct, I had used this simple method to get what I want, but I was getiint the following errors

    1.Not proxied and
    2.peer certificate is not varified
    And fact is that Client is saying that if you are having SSL implementation to connect to thier gateway it will not ask for certificae.

    Can you please look at the following code.
    use strict; use Data::Dumper; use LWP::UserAgent; use HTTP::Request; use HTTP::Headers; use LWP::Debug qw(+); my $method = 'POST'; my $host = 'orbitalvar1.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>1009</Exp>'. '<CurrencyCode>840</CurrencyCode>'. '<CurrencyExponent>2</CurrencyExponent>'. '<CardSecVal>213</CardSecVal>'. '<AVSzip>33408</AVSzip>'. '<AVSaddress1>test address</AVSaddress1>'. '<AVScity>miami</AVScity>'. '<AVSstate>FL</AVSstate>'. '<AVSphoneNum>5618926384</AVSphoneNum>'. '<AVSname>Raj Malahotra</AVSname>'. '<AVScountryCode>US</AVScountryCode>'. '<AVSDestzip>33408</AVSDestzip>'. '<AVSDestaddress1>Dest addresss</AVSDestaddres +s1>'. '<AVSDestcity>testcity</AVSDestcity>'. '<AVSDeststate>FL</AVSDeststate>'. '<AVSDestname>Raj Malahotra</AVSDestname>'. '<AVSDestcountryCode>US</AVSDestcountryCode>'. '<CustomerProfileFromOrderInd>A</CustomerProfi +leFromOrderInd>'. '<OrderID>091933208935</OrderID>'. '<Amount>1500</Amount>'. '<BMLShippingCost>1500</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(); #$ENV{HTTPS_PROXY} = '192.168.9.10:443'; $UserAgent->env_proxy; my $host_response = $UserAgent->request($HTTP_req); print STDERR "\n========= headers ======== \n" . Dumper($header); + print STDERR "\n========= request ======== \n" . Dumper($HTTP_req +); print STDERR "\n========= response ======== \n" . Dumper($host_re +sponse); __END__
    Please suggest what I am missing while using LWP::UserAgent. Thanks, SHAM.....
      Firstly, please use <readmore> tags when you post large amounts of code.

      I was getiint the following errors

      1.Not proxied and
      Please read the Crypt::SSLeay documentation.

      Don't use LWP's env_proxy method, it doesn't work properly in all situations with HTTPS. Set the HTTPS_PROXY variable in the environment, Crypt::SSLeay will pick up on it and use the appropriate arguments to the SSL connect() method. You may also need to set the HTTPS_PROXY_USERNAME and HTTPS_PROXY_PASSWORD variables (if the proxy requires basic authentication).

      2.peer certificate is not varified
      And fact is that Client is saying that if you are having SSL implementation to connect to thier gateway it will not ask for certificae.
      So does the server require peer certificate authentication or not?

      If it does, you'll need to set the HTTPS_CERT_FILE and HTTPS_KEY_FILE environment variables, so that Crypt::SSLeay will know where to look for those files.

      Can you please look at the following code.
      I have no idea what you're doing with all that header manipulation... can I presume that the payment gateway documentation prescribes those actions?

      -David