Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

cURL problem

Featured Replies

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;
}

?>

 

I have tried using an $xml variable as well as XML_PAYLOAD as the parameter in the CURLOPT_POSTFIELDS without any success. From looking at the above code, does anybody have any idea where Im going wrong?

 

Thanks

I am using the following code and having problems:

[snip]

From looking at the above code, does anybody have any idea where Im going wrong?

It might help if you said what actually is happening :) For example, nothing, or a visible error (and what it reads), or something bizarre?! Make sure all error reporting is on (e.g. add error_reporting(E_ALL) at the top) to help debugging. I'm guessing this is template code supplied by the vendor, in which case what have you changed which may mean it doesn't work?

  • Author

Hi,

 

Thanks for the reply. I don't think there is actually an error, but it doesn't work.

 

In my previous code, you will see a section which says:

 

$result    =    curl_exec($handle);
print "<textarea rows='10' cols='80'>";
print htmlentities($result)."hello";
print "</textarea>";
//exit(); 
var_dump($result);

 

This section is for testing, to make sure the XML bering sent is valid. When I try and output it into the textarea, nothing shows up. And the

var_dump($result);

returns bool(false).

 

Any ideas why nothing is being returned?

 

Thanks

See if cURL outputs any error messages:

 

// ... (stuff before)
$result    =    curl_exec($handle);
echo curl_errno($handle) . "\n";
echo curl_error($handle) . "\n";
// ... (the rest)

  • Author

Thanks for the tip. Im getting the foillowing error:

 

6 name lookup timed out

 

Not sure what this means though?

 

Thanks again.

  • Author

Tried it again and I'm now getting this error:

 

7 couldn't connect to host

 

Thanks.

Are you able to connect to that site using any other method, from the same machine as your code is running on? For example via a Web browser or shell, are you able to query: https://secure2.epdq.co.uk:11500/

 

The DNS resolution and connection failure sound like networking issues at your end (since the URL is working fine for me). It may also be necessary to tell cURL to accept SSL but ignore the certificate, but not certain about that.

  • Author

Yes I can connect to the site using a browser just fine.

 

Do you have any other ideas? Im pretty stumped as Im new to cURL. Ive been looking round on the net for a solution but nobody seems tro have one.

 

Thanks

Have you tried using a different cURL example to connect to a known-good HTTP (insecure) URL in PHP, and see if that works? If it does, there's either a problem with the lines of code in your template (in which case, adapt the new example to suit) or with SSL handling. If you can't connect with a new script, there may be a problem with the installed cURL library.

Just struck me that the other possibility is a firewall which is allowing your browser but not your Web server. Do you have one in hardware or installed software? Temporarily disable it and try again.

  • Author

OK I tried linking to the Apple site and that seems to work. There is just an issue when I link to the site I posted above. Do you know why this site could be different?

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.