cURL problems - please help!

Discussion in 'PHP' started by highway7, Feb 12, 2010.

  1. #1
    Hi,

    I am using cURL to send XML from site A to site B. Site B the processes this data and returns XML info to site A. Site A then parses and displays this XML. I am using the following code and having problems:

    <?php
    
    // Define vars
    $endpoint    =    'https://secure2.epdq.co.uk:11500/';
    
    //Define payload
     define('XML_PAYLOAD', '<EngineDocList><DocVersion>1.0</DocVersion><EngineDoc><ContentType>OrderFormDoc</ContentType><User><Name>URAdmin</Name><Password>TT2Access</Password><ClientId DataType="S32">49868</ClientId></User><Instructions><Pipeline>Payment</Pipeline></Instructions><OrderFormDoc><Mode>P</Mode><Id>01</Id><Consumer><Email>john@urbanriver.com</Email><BillTo><Location><Address><FirstName>John</FirstName><LastName>Barker</LastName><Street1>113 Borough Road</Street1><Street2></Street2><Street3></Street3><City>Jarrow</City><StateProv>Tyne and Wear</StateProv><PostalCode>NE32</PostalCode><Country>826</Country></Address></Location></BillTo><ShipTo><Location><Address><FirstName>Jane</FirstName><LastName>Smith</LastName><Street1>22 High Street</Street1><Street2></Street2><Street3></Street3><City>Northampton</City><StateProv>Northants</StateProv><PostalCode>NN1 1NN</PostalCode><Country>826</Country></Address></Location></ShipTo><PaymentMech><CreditCard><Type DataType="S32">1</Type><Number>4921819895586270</Number><Expires DataType="ExpirationDate" Locale="826">07/12</Expires><IssueNum></IssueNum><StartDate DataType="StartDate">04/09</StartDate><Cvv2Indicator>1</Cvv2Indicator><Cvv2Val>703</Cvv2Val></CreditCard></PaymentMech></Consumer><Transaction><Type>Auth</Type><CurrentTotals><Totals><Total DataType="Money" Currency="826">1</Total></Totals></CurrentTotals><CardholderPresentCode DataType="S32">7</CardholderPresentCode><PayerSecurityLevel DataType="S32"></PayerSecurityLevel><PayerAuthenticationCode></PayerAuthenticationCode><PayerTxnId></PayerTxnId></Transaction></OrderFormDoc></EngineDoc></EngineDocList>');
    
    // Init
    $handle    =    curl_init(); 
    $xml = '<EngineDocList><DocVersion>1.0</DocVersion><EngineDoc><ContentType>OrderFormDoc</ContentType><User><Name>URAdmin</Name><Password>TT2Access</Password><ClientId DataType="S32">49868</ClientId></User><Instructions><Pipeline>Payment</Pipeline></Instructions><OrderFormDoc><Mode>P</Mode><Id>01</Id><Consumer><Email>john@urbanriver.com</Email><BillTo><Location><Address><FirstName>John</FirstName><LastName>Barker</LastName><Street1>113 Borough Road</Street1><Street2></Street2><Street3></Street3><City>Jarrow</City><StateProv>Tyne and Wear</StateProv><PostalCode>NE32</PostalCode><Country>826</Country></Address></Location></BillTo><ShipTo><Location><Address><FirstName>Jane</FirstName><LastName>Smith</LastName><Street1>22 High Street</Street1><Street2></Street2><Street3></Street3><City>Northampton</City><StateProv>Northants</StateProv><PostalCode>NN1 1NN</PostalCode><Country>826</Country></Address></Location></ShipTo><PaymentMech><CreditCard><Type DataType="S32">1</Type><Number>4921819895586270</Number><Expires DataType="ExpirationDate" Locale="826">07/12</Expires><IssueNum></IssueNum><StartDate DataType="StartDate">04/09</StartDate><Cvv2Indicator>1</Cvv2Indicator><Cvv2Val>703</Cvv2Val></CreditCard></PaymentMech></Consumer><Transaction><Type>Auth</Type><CurrentTotals><Totals><Total DataType="Money" Currency="826">1</Total></Totals></CurrentTotals><CardholderPresentCode DataType="S32">7</CardholderPresentCode><PayerSecurityLevel DataType="S32"></PayerSecurityLevel><PayerAuthenticationCode></PayerAuthenticationCode><PayerTxnId></PayerTxnId></Transaction></OrderFormDoc></EngineDoc></EngineDocList>');
    //
    // Options
    //
    curl_setopt($handle, CURLOPT_URL, $endpoint); 
    
    // 12 seconds timeout
    curl_setopt($handle, CURLOPT_TIMEOUT, 12);
    
    // Allow redirects
    curl_setopt($handle, CURLOPT_FOLLOWLOCATION, 1);               
    
    // Return result (expecting XML?)
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1); 
    
    // The actual "payload"
    curl_setopt($handle, CURLOPT_POST, 1);
    curl_setopt($handle, CURLOPT_POSTFIELDS, $xml); 
    
    // SSL info
    //curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, TRUE);
    //curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, 2);
    //curl_setopt($handle, CURLOPT_CAINFO, "/certs/certificate.crt");
    
    
    // Run/return results
    $result    =    curl_exec($handle);
    print "<textarea rows='10' cols='80'>";
      print htmlentities($result)."hello";
      print "</textarea>";
      //exit(); 
    var_dump($result);
    
    // You'd probabaly wana check errors too.
    
    
    // Close.
    curl_close($handle);
    
    //
    // Now we'll want to parse the XML that the endpoint returns (the payment processor site)
    $xml_return    =    simplexml_load_string($result);
    
    if ($xml_return->result == 'OK')
    {
       echo 'system processed payment';
    }
    else
    {
        echo $xml_return->result;
    }
    
    ?>
    PHP:

    I get the following error:

    7 couldn't connect to host
    HTML:
    However, when I try to use the apple website as a test, it seems to work OK. Does anybody have any idea why this is not working?

    Thanks in advance.
     
    highway7, Feb 12, 2010 IP
  2. 0x00

    0x00 Well-Known Member

    Messages:
    122
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    115
    #2
    Use CURLOPT_PORT instead of:

    $endpoint = 'https://secure2.epdq.co.uk:11500/';


    so it goes like:

    $endpoint = 'https://secure2.epdq.co.uk';

    and

    curl_setopt($handle, CURLOPT_PORT , 11500);
     
    0x00, Feb 12, 2010 IP
  3. highway7

    highway7 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi,

    Thanks for the reply.

    I tried what you suggested without success. I'm still getting the same error. Do you have any other ideas?

    All suggestions are appreciated.

    Thanks.
     
    highway7, Feb 12, 2010 IP
  4. HivelocityDD

    HivelocityDD Peon

    Messages:
    179
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Your host is using https.. that can be one of the reason and I see you have commented this line

    
    //curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, TRUE);
    
    Code (markup):

    instead of this try the following to disallow SSL verification

    
    
    curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
    
    PHP:
     
    HivelocityDD, Feb 12, 2010 IP